Created
March 8, 2022 00:20
-
-
Save ktskumar/c46b886061bc198185c008b6f78be6e1 to your computer and use it in GitHub Desktop.
Copy web-part from one page to another modern page in SharePoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Below code uses the PnP JS and helps to copy the webpart from one page to another page in modern SharePoint page | |
*/ | |
import { sp } from "@pnp/sp/presets/all"; | |
(async () => { | |
const page = await sp.web.loadClientsidePage("/sites/portal/SitePages/page2.aspx"); | |
const control = page.sections[1].columns[0].getControl(0); | |
console.log("Page: ", page.sections[1].columns[0].getControl(0)); | |
const targetPage = await sp.web.loadClientsidePage("/sites/portal/SitePages/home.aspx"); | |
targetPage.addSection().addControl(control); | |
await targetPage.save(); | |
})().catch(console.log) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment