pnp / pnpjs

Fluent JavaScript API for SharePoint and Microsoft Graph REST APIs
https://pnp.github.io/pnpjs/
Other
753 stars 305 forks source link

How do I get the Id of age page I just created with addClientsidePage? #2961

Closed mikezimm closed 5 months ago

mikezimm commented 5 months ago

What version of PnPjs library you are using

3.x

Minor Version Number

3.X

Target environment

SharePoint Framework

Additional environment details

Windows 10

Question/Request

Docs referenced: https://pnp.github.io/pnpjs/sp/clientside-pages/#create-using-iwebaddclientsidepage

I am successfully using this method to create a new clientside page: const page = await sp.web.addClientsidePage("mypage1");

However, I need to get the Id of the newly created page. I couldn't find any example other than one that said to use page.id but that does not work.

I'm guessing it's pretty easy, but I have not found a way to get it.

I've tried getting it by fetching the latest items right after it's done but if I am creating multiple ones sync mode, the latest Id isn't necessarily the correct one.

Thanks!

patrick-rodgers commented 5 months ago

I think you need to make a request for the page information.

// page is an instance of the page data object
const page = await sp.web.addClientsidePage("mypage1");

// info is the data for that page
const info = await page();

There are more examples of loading pages in the docs.

patrick-rodgers commented 5 months ago

Closing this issue as answered. If you have additional questions or we did not answer your question, please open a new issue, ref this issue, and provide any additional details available. Thank you!

github-actions[bot] commented 5 months ago

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.