SPFx save selected user to a people column?

%3CLINGO-SUB%20id%3D%22lingo-sub-462167%22%20slang%3D%22en-US%22%3ESPFx%20save%20selected%20user%20to%20a%20people%20column%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-462167%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI%20am%20trying%20to%20fetch%20the%20name%20of%20a%20user%20with%20the%20PeoplePicker%20component%20and%20then%20save%20it%20in%20a%20list%20that%20contains%20a%20Person%20column.%26nbsp%3B%3C%2FP%3E%3CP%3EThere%20is%20something%20in%20the%20method%20that%20create%20the%20new%20item%20in%20the%20list%20that%20is%20wrong%20and%20can't%20create%20the%20item.%26nbsp%3B%3C%2FP%3E%3CP%3EJust%20for%20testing%20I%20created%20a%20new%20column%20of%20type%20single%20text%20and%20the%20method%20was%20available%20to%20create%20the%20new%20item%2C%20so%20there%20is%20something%20that%20I%20am%20missing%20in%20order%20to%20save%20the%20name%20in%20the%20Person%20column.%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20is%20what%20I%20have%20until%20now%3A%3C%2FP%3E%3CP%3EThe%20PeoplePicker%20from%20pnp%2Fspfx-controls%3A%3C%2FP%3E%3CDIV%3E%3CPRE%3E%3CSPAN%3E%26lt%3B%3C%2FSPAN%3E%3CSPAN%3EPeoplePicker%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%20%20%20%20%20%20%20%20%20%20context%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%7Bthis%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3Eprops%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3Econtext%3C%2FSPAN%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%20%20%20%20%20%20%20%20%20%20titleText%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%22Sales%20Manager%22%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%20%20%20%20%20%20%20%20%20%20personSelectionLimit%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3CSPAN%3E1%3C%2FSPAN%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%20%20%20%20%20%20%20%20%20%20groupName%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3CSPAN%3E%22%22%3C%2FSPAN%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%20%3CSPAN%3E%2F%2F%20Leave%20this%20blank%20in%20case%20you%20want%20to%20filter%20from%20all%20users%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%20%20%20%20%20%20%20%20%20%20showtooltip%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%7Btrue%7D%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%20%20%20%20%20%20%20%20%20%20isRequired%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%7Bfalse%7D%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%20%20%20%20%20%20%20%20%20%20disabled%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%7Bfalse%7D%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%20%20%20%20%20%20%20%20%20%20selectedItems%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%7Bthis%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3E_getManager%3C%2FSPAN%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%20%20%20%20%20%20%20%20%20%20principalTypes%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3CSPAN%3E%5B%3C%2FSPAN%3E%3CSPAN%3EPrincipalType%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3EUser%3C%2FSPAN%3E%3CSPAN%3E%5D%3C%2FSPAN%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%2F%26gt%3B%3C%2FSPAN%3E%3C%2FPRE%3E%3C%2FDIV%3E%3CP%3EThe%20_getManager%20method%20that%20update%20the%20state%3A%3C%2FP%3E%3CDIV%3E%3CPRE%3E%3CSPAN%3Eprivate%3C%2FSPAN%3E%20%3CSPAN%3Easync%3C%2FSPAN%3E%20%3CSPAN%3E_getManager%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3Eitems%3C%2FSPAN%3E%3CSPAN%3E%3A%3C%2FSPAN%3E%20%3CSPAN%3Eany%3C%2FSPAN%3E%3CSPAN%3E%5B%5D)%20%7B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%20%20%20%20%20await%3C%2FSPAN%3E%20%3CSPAN%3Ethis%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3EsetState%3C%2FSPAN%3E%3CSPAN%3E(%7B%20%3C%2FSPAN%3E%3CSPAN%3Epeople%3A%3C%2FSPAN%3E%20%3CSPAN%3Eitems%3C%2FSPAN%3E%3CSPAN%3E%5B%3C%2FSPAN%3E%3CSPAN%3E0%3C%2FSPAN%3E%3CSPAN%3E%5D.%3C%2FSPAN%3E%3CSPAN%3Etext%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3EtoString%3C%2FSPAN%3E%3CSPAN%3E()%20%7D)%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FPRE%3E%3CP%3EAnd%20this%20is%20the%20_create%20method%20that%20should%20save%20the%20item%20in%20the%20list%3A%3C%2FP%3E%3CDIV%3E%3CPRE%3E%3CSPAN%3Eprivate%3C%2FSPAN%3E%20%3CSPAN%3E_createItem%3C%2FSPAN%3E%3CSPAN%3E()%3C%2FSPAN%3E%3CSPAN%3E%3A%3C%2FSPAN%3E%20%3CSPAN%3Evoid%3C%2FSPAN%3E%3CSPAN%3E%20%7B%3C%2FSPAN%3E%3CBR%20%2F%3E%20%20%20%20%20%20%3CSPAN%3Epnp%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3Esp%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3Eweb%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3Elists%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3EgetByTitle%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3E%22test%22%3C%2FSPAN%3E%3CSPAN%3E).%3C%2FSPAN%3E%3CSPAN%3Eitems%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3Eadd%3C%2FSPAN%3E%3CSPAN%3E(%7B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%20%20%20%20%20%20%20%20%20%20%20%20Title%3A%3C%2FSPAN%3E%20%3CSPAN%3Ethis%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3Estate%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3ETitle%3C%2FSPAN%3E%3CSPAN%3E%2C%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%20%20%20%20%20%20%20%20%20%20%20%20people%3A%3C%2FSPAN%3E%20%3CSPAN%3Ethis%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3Estate%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3Epeople%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%20%20%20%20%20%20%7D)%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FPRE%3E%3CP%3EThis%20same%20_create%20code%20works%20if%20I%20save%20the%20people%20in%20the%20state%20to%20a%20single%20line%20column.%20But%20with%20a%20Person%20column%20I%20get%20this%20message%20in%20the%20console%3A%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CSPAN%3EA%20'PrimitiveValue'%20node%20with%20non-null%20value%20was%20found%20when%20trying%20to%20read%20the%20value%20of%20a%20navigation%20property%3B%20however%2C%20a%20'StartArray'%20node%2C%20a%20'StartObject'%20node%2C%20or%20a%20'PrimitiveValue'%20node%20with%20null%20value%20was%20expected.%3C%2FSPAN%3E%3C%2FPRE%3E%3CP%3EAnd%20I%20can't%20find%20the%20waty%20to%20make%20it%20works.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBest%20regards%3C%2FP%3E%3CP%3EAmerico%3C%2FP%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-462167%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPnP%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
Regular Contributor

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

0 Replies