pnp / pnpjs

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

Add/Update methods no longer returning data as of V4 #3037

Closed SPWizard01 closed 1 month ago

SPWizard01 commented 1 month ago

What version of PnPjs library you are using

4.x

Minor Version Number

0.1

Target environment

other (enter in the "Additional environment details" area below)

Additional environment details

Standard setup of in-browser pnp library.

Question/Request

As of v4 when adding an item to the list the .add() method returns void as well as update.

How do I know the item Id of the item I just added to the list? Consider a scenario where the list is heavily used, getting "last" item won't cut it.

juliemturner commented 1 month ago

@SPWizard01 - I just took a look to verify that there wasn't a bug and according to the source code the add method on list items returns "any". Then I tested it and got the data on the recently added item, which includes the Id. The change for version 3 was that we no longer return an object with the data and item properties we just return the data as a pass through from the REST api like we do for any other call.

So v4 looks like this:

const item = await sp.web.lists.getByTitle("pnplist").items.add({Title: 'Hello World'});
const id = item.ID;
juliemturner commented 1 month ago

I'm going to close this issue as answered. If you have further issues, please feel free to create a new issue and reference this one.

github-actions[bot] commented 1 month 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.