2

I'm trying to insert a user field value using people picker in SPFX solution using PNP, but I'm getting the below error. I'm copying the code below which I'm using and the error too which I'm getting again and again.

Control :

<PeoplePicker
                context={this.props.context}
                titleText="People Picker"
                personSelectionLimit={3}
                groupName={""} // Leave this blank in case you want to filter from all users
                showtooltip={true}
                isRequired={true}
                disabled={false}
                ensureUser={true}
                selectedItems={this._getPeoplePickerItems}
                showHiddenInUI={false}
                principalTypes={[PrincipalType.User]}
                resolveDelay={1000} />

Binding :

@autobind 
  private _getPeoplePickerItems(items: any[]) {
    console.log('Items:', items);

    let selectedUsers = [];
    for (let item in items) {
      selectedUsers.push(items[item].id);
    }

    this.setState({ addUsers: selectedUsers });
  }

  @autobind 
  private addSelectedUsers(): void {  
    sp.web.lists.getByTitle("test").items.add({
      Title: 'test1',
      testcol:'test2',
     // Users: this.context.addUsers[] 
      Users: 11
    }).then(i => {
        console.log(i);
    });
  } 
}

I'm passing static user ID i.e 11 just to make sure that at-least static value can be added , but still it throws me the below 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 '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 HttpRequestError (parsers.ts:13) at parsers.ts:19

Any kind of help would be much appreciated. Also I would also appreciate the reference of any blogs where this simple operation of adding a people picker value in list is being demonstrated.

1

If the field name is "Users" you can specify it as "UsersId" in your request body like so if you want to set it by user ID:

sp.web.lists.getByTitle("test").items.add({
      Title: 'test1',
      testcol:'test2',
      UsersId: 11
    })
1
  • Much Thanks!! I was struggling with this since a week. – Muskan Apr 21 '20 at 4:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.