Trying to add list item using pnp

I am trying to create child records using pnp and I'm getting an error I just can't figure out.

This is my code under a button:

pnp.sp.web.lists.getByTitle('Tickets').items.add({
    Title: 'Employee Seperation - Securing the Human',
    Provider: fd.field('Provider').value.LookupId,
    Requestor: { results: [9] },
    Priority: 3,
    Urgency: 2,
    Status: 6,
    Technician: { results: [9] },
    Parent: fd.itemId
});

This is the errors I'm getting:

POST https://xxxxxx.sharepoint.com/sites/helpdesk/_api/web/lists/getByTitle('Tickets')/items 400 (Bad Request) spform.js:16

spform.js:30
Uncaught (in promise) Error: Error making HttpClient request in queryable [400] Bad Request ::> {"odata.error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"A 'PrimitiveValue' node with non-null value was found when trying to read the value of a navigation property; however, a 'StartArray' node, a 'StartObject' node, or a 'PrimitiveValue' node with null value was expected."}}}
at new t (spform.js:30)
at Function. (spform.js:30)
at spform.js:30
at Object.next (spform.js:30)
at a (spform.js:30)

The url in the 400 error does hit the list and returns all the items, so I know its trying to work, I thought it was about not satisfying all of the required fields, but after adding all those, it still isn't working. It might have to do with the People fields, but per the PNPjs documentation, what I have should work.

So, I'm stumped.

My guess is Parent is a lookup, maybe try ParentId: fd.itemId

1 Like

@smithme,

For Person or Group and Lookup fields, you need to add Id suffix to the internal name of the field:
ParentId
RequestorId

Also, the syntax for single and multiple selection Person or Group fields is different. Thus, if Technician and Requestor fields are single choice, they should be updated like this:

pnp.sp.web.lists.getByTitle('Tickets').items.add({
    Title: 'Employee Seperation - Securing the Human',
    Provider: fd.field('Provider').value.LookupId,
    RequestorId: 9,
    Priority: 3,
    Urgency: 2,
    Status: 6,
    TechnicianId: 9,
    ParentId: fd.itemId
});
1 Like