Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
SPWizard01 opened this issue May 20, 2024 · 3 comments
Closed

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

SPWizard01 opened this issue May 20, 2024 · 3 comments

Comments

@SPWizard01
Copy link

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
Copy link
Collaborator

@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
Copy link
Collaborator

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.

Copy link

github-actions bot commented Jun 1, 2024

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 github-actions bot locked and limited conversation to collaborators Jun 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants