pnp / pnpjs

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

Documentation is incorrect #2947

Closed JamyJamal closed 5 months ago

JamyJamal commented 6 months ago

Major Version

4.x

Minor Version Number

1.0 (not sure about the version as I am using it as part of Plumsail forms)

Target environment

Browser App (Hosted external to Microsoft 365 platform)

Additional environment details

In your documentation, you say that to update a Multiple User field, you need to use the following format:

const i = await sp.web.lists.getByTitle("PeopleFields").items.add({
  Title: getGUID(),
  User1Id: 9, // allows a single user
  **User2Id: [16, 45] // allows multiple users**
});

Unfortunately, for the Multiple user field, it doesn't work, you actually have to use the following format:

const i = await sp.web.lists.getByTitle("PeopleFields").items.add({
  Title: getGUID(),
  User1Id: 9, // allows a single user
  **User2Id: {results: [16, 45]} // allows multiple users**
});

If you could update your documentation it would be very helpful. As I am sure I am not the only one who has come across this!

Thanking you much!

Jamal

Expected or Desired Behavior

Trying to update a multiple person field with:

const i = await sp.web.lists.getByTitle("PeopleFields").items.add({
  Title: getGUID(),
  User1Id: 9, // allows a single user
  **User2Id: [16, 45] // allows multiple users**
});

Observed Behavior

I got this response: { "odata.error": { "code": "-1, Microsoft.SharePoint.Client.InvalidClientQueryException", "message": { "lang": "en-US", "value": "A node of type 'PrimitiveValue' was read from the JSON reader when trying to read the entries of a feed. A 'StartObject' or 'EndArray' node was expected." } }

Steps to Reproduce

Just do any update when you use an array to update a multi person field.

As stated before, the way I got it to work was to use the following format:

const i = await sp.web.lists.getByTitle("PeopleFields").items.add({
  Title: getGUID(),
  User1Id: 9, // allows a single user
  **User2Id: {results: [16, 45]} // allows multiple users**
});
patrick-rodgers commented 6 months ago

Are you really using version 4 from the nightly builds? Just curious so we are investigating the correct thing.

patrick-rodgers commented 5 months ago

I can't duplicate your findings. Can you share more information on your configuration? As best I can tell the docs are correct in this case. Are you changing the odata mode? As well, will ask again what version of the library you are really using?

JamyJamal commented 5 months ago

Apologies, I am not sure what version I am using as it is part of plumsail forms implementation within their product, I assumed it was the latest version they are using. I will try and find out, it most likely is an earlier version...

On Wed, 13 Mar 2024, 13:55 Patrick Rodgers, @.***> wrote:

I can't duplicate your findings. Can you share more information on your configuration? As best I can tell the docs are correct in this case. Are you changing the odata mode? As well, will ask again what version of the library you are really using?

— Reply to this email directly, view it on GitHub https://github.com/pnp/pnpjs/issues/2947#issuecomment-1994464218, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALYIJMW2LI6GNCDXQGN4LIDYYBLDNAVCNFSM6AAAAABD37A76WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOJUGQ3DIMRRHA . You are receiving this because you authored the thread.Message ID: @.***>

bcameron1231 commented 5 months ago

Closing this due to inactivity. If you continue to have issues please open a new issue, link to this issue, and provide any additional details available. Thanks!

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