pnpjs icon indicating copy to clipboard operation
pnpjs copied to clipboard

Unable to add "Site Activity Web-part" Programatically.

Open pavan2920 opened this issue 8 years ago • 5 comments

Hi Team,

We add the "site Activity" webpart using the following properties in modern page.

new ClientSideWebpart('SiteActivityWebPart', 'Show recent activities from your site.', { "maxItems": 9, }, 'eb95c819-ab8f-4689-bd03-0c2d65d47b1f', null, { "searchablePlainTexts": {}, "imageSources": {}, "links": {} })

We were using "@pnp/common": "^1.2.3", "@pnp/logging": "^1.2.3", "@pnp/odata": "^1.2.3", "@pnp/pnpjs": "^1.1.4", "@pnp/sp": "^1.2.3", ,But due new update, we can see a new property in the webpart. (seen in ?maintenancemode=true) i.e. "htmlStrings": {}

But, when i try to add this property its throwing error. (updated all the above packages to new version) image

What would be the fix for it. ?

Also, with the Existing properties the webpart does not appear in the page in View/Edit or maintenancemode.

Thanks & Regards, Pavan.

pavan2920 avatar Dec 03 '18 05:12 pavan2920

In the case of site activity webpart htmlProperties can be omitted.

This worked for me for creation, update, with and without htmlProperties:

import { sp, ClientSidePage, ClientSideWebpart, ClientSideText } from '@pnp/sp';

(async () => {

  // const page = await sp.web.addClientSidePage('SamplePage01.aspx', 'Sample Page 01');

  // Getting existing page
  const { ServerRelativeUrl } = await sp.web.select('ServerRelativeUrl').get();
  const pageFile = sp.web.getFileByServerRelativeUrl(`${ServerRelativeUrl}/SitePages/SamplePage01.aspx`);
  const page = await ClientSidePage.fromFile(pageFile);

  page.sections = [];
  const section = page.addSection();

  section.addControl(
    new ClientSideWebpart(
      'SiteActivityWebPart', null, {
        maxItems: 4
      },
      'eb95c819-ab8f-4689-bd03-0c2d65d47b1f',
      // {
      //  htmlStrings: {},
      //  searchablePlainTexts: {},
      //  imageSources: {},
      //  links: {}
      // } as any
    )
  );

  await page.save();

})()
  .then(_ => console.log('Done'))
  .catch(console.log);

koltyakov avatar Dec 03 '18 08:12 koltyakov

Hi @koltyakov , Tried the same thing but the webpart is not getting added.

image

And here is the package.json file image

Did it worked for you ? IF yes, can you share screenshot of package.json

Regards, Pavan.

pavan2920 avatar Dec 03 '18 09:12 pavan2920

Sure thing, it works for me. Before providing any samples I make sure they work using recent version of the library. Yes, it was 1.2.6.

webpartcreations

koltyakov avatar Dec 03 '18 09:12 koltyakov

Going to close this as answered. You can also see the new sample showing how to add a Yammer webpart which applies to each of the types. Please reopen if you need to continue the conversation. Thanks!

patrick-rodgers avatar Dec 12 '18 15:12 patrick-rodgers

This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.

github-actions[bot] avatar May 22 '21 01:05 github-actions[bot]