Pnpjs: Issue when creating a new item with user field

Created on 23 May 2019  路  5Comments  路  Source: pnp/pnpjs

Library : "@pnp/sp": "^1.3.2",
error
parsers.ts:13 Uncaught (in promise) Error: Error making HttpClient request in queryable [400] ::> {"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."}}}
at new HttpRequestError (parsers.ts:13)

await sp.web.lists.getByTitle("TEST").items.add({

    Title: "Title",
    usern:11
      }).then((iar: ItemAddResult) => {
    console.log(iar);
at parsers.ts:19
code answered question

Most helpful comment

The payload is the object you pass to the operation. Based on this piece of code usern:11 it's obvious that it's incorrect. A lookup/people picker entity name can't be usern. Lookup id entity names are always suffixed with Id. E.g. if the field internal name MyUser it's entity name in the payload must be MyUserId.

All 5 comments

The payload is incorrect. Please check the docs.

sorry what does payload mean . I am using the below code
sp.web.lists.getByTitle("PeopleFields").items.add({
Title: getGUID(),
User1Id: 9, // allows a single user
User2Id: {
results: [ 16, 45 ] // allows multiple users
}
}).then(i => {
console.log(i);
});

The payload is the object you pass to the operation. Based on this piece of code usern:11 it's obvious that it's incorrect. A lookup/people picker entity name can't be usern. Lookup id entity names are always suffixed with Id. E.g. if the field internal name MyUser it's entity name in the payload must be MyUserId.

ok let me check

@koltyakov oops now it get :-) thank you for helping.

Was this page helpful?
0 / 5 - 0 ratings