SharePoint/PnP-JS-Core

Having issues adding User and Lookup fields to List

Closed this issue · 2 comments

Category

[ ] Enhancement

[ ] Bug

[ #] Question

Version

Hi there

I'm trying to add User and Lookup value to a list using the sp-pnp-js library, following instructions from this page: https://github.com/SharePoint/PnP-JS-Core/wiki/Working-With:-Items

But i keep getting this error when attempting to include any of these fields (lookup and user):
"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"

Not sure what i'm doing wrong???

This is my code:
web.lists.getByTitle('Some listName').items.add({ Title: title.value, SiteUserId: userId, SiteTemplateUrl: 1 }).then((result: ItemAddResult) => { console.log(result); this.close(); }).catch(error => { console.log(error); });

Any help as usual is greatly appreciated, cheers

Hey Mike,

Are you sure you provide the correct field entity names? E.g. is SiteTemplateUrl a Lookup? If so, its name is 100% sure is incorrect, should be SiteTemplateUrlId, lookup field entity names in REST are ended with Id. Please check this on how to resolve the names.

Yes, yes. Many many thanks!

I didn't pay attention to the accompanying text on that page which explained that and'Id' must be added to the end of the internal name. I looked at the code and was just trying to race ahead.

It's all working now.

Cheers for speedy reply 👍