Forum Discussion
SPFx save selected user to a people column?
Hi,
I am trying to fetch the name of a user with the PeoplePicker component and then save it in a list that contains a Person column.
There is something in the method that create the new item in the list that is wrong and can't create the item.
Just for testing I created a new column of type single text and the method was available to create the new item, so there is something that I am missing in order to save the name in the Person column.
This is what I have until now:
The PeoplePicker from pnp/spfx-controls:
<PeoplePicker
context={this.props.context}
titleText="Sales Manager"
personSelectionLimit={1}
groupName={""} // Leave this blank in case you want to filter from all users
showtooltip={true}
isRequired={false}
disabled={false}
selectedItems={this._getManager}
principalTypes={[PrincipalType.User]}
/>
The _getManager method that update the state:
private async _getManager(items: any[]) {
await this.setState({ people: items[0].text.toString() });
}
And this is the _create method that should save the item in the list:
private _createItem(): void {
pnp.sp.web.lists.getByTitle("test").items.add({
Title: this.state.Title,
people: this.state.people
});
}
This same _create code works if I save the people in the state to a single line column. But with a Person column I get this message in the console:
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.
And I can't find the waty to make it works.
Best regards
Americo