Is your feature request related to a problem? Please describe.
We have a site with about 100 pages created from a template page. The template had 3 search results webparts. Each showing different data.
The Query template property of one of those search results webpart in all the pages had to be updated. Updating it manually was an option however it would have been time consuming.
(I hopred the Result Source Id / Name property of the webpart was set and it would have been an easier task. However that was not the case).
So I wrote a simple script with PnP JS and used the SP.Editor Edge extension to run that.
const page = await sp.web.loadClientsidePage(fileRef);
const section = page.sections[4];
const column = section && section.columns[1];
const part = column && column.getControl(0);
const wpTitle = part && part.json.webPartData.properties.webPartTitle;
if(wpTitle === "Apps") {
console.log(part.json.webPartData.properties.queryTemplate);
part.json.webPartData.properties.queryTemplate += " IsMainPageOWSBOOL:1"
savePage = true;
}
if (savePage) {
console.log(" Saving page with updated query for Apps");
await page.save();
}
If the same was the case for other properties of the webpart then the script needs to be changed to update those other properties.
Describe the solution you'd like
So, what I want to know is:
Additional context
Sorry if the question is not related to this repository.
Hi @anoopt, sorry but this question is not related to the PnP Modern Search solution. I suggest you to use the Techcommunity forum. Thanks!
@anoopt See https://github.com/microsoft-search/pnp-modern-search/issues/907 for some valuable info to get you started.
Thank you @wobba . Using that information, I have created an SPFx extension to copy settings of PnP Search results webpart from one page to another.
Basically copying json.webpartData.properties and json.webpartData.dynamicDataValues of a webpart in one page to the webpart in other pages using PnP JS.
Do you and @FranckyC think there is anything else that needs to be copied?
Both v3 and v4 now have the ability in the web part pane to import/export the json settings per web part. You can look at what is exported.
It uses this control https://pnp.github.io/sp-dev-fx-property-controls/controls/PropertyPanePropertyEditor/ so you can take a look at the code for that one as well.