Saving Person or Group field with REST

Does anyone know how to save a Person field using REST?

I tried the following and it works:

{ "__metadata": { "type": "SP.Data.SomeListListItem" } , "MyPersonFieldId" : 1 } 

But this only works if you know the identifier. I do not have it! How can I get it? I have the key i.0#w|domain\userName .

I tried the following and it does not work either:

 { "__metadata": { "type": "SP.Data.SomeListListItem" } , "MyPersonField" : { "__metadata": { "type": "SP.Data.UserInfoItem" }, "Name": "i.0#w|domain\userName" } } 

Any ideas? Thanks!

+4
source share
3 answers

I did not do this with the Person field, but I did something similar with a metadata-driven field. Basically, I had to pass additional information as an object to create the value in the field.

See if passing the user ID along with the name works. I am going to try this myself, as I have the same need.

 { "MyPersonField": { "Name": "i.0#w|domain\userName", "ID": 1 } } 

EDIT: Well, updating this field is easier than I thought. I was able to perform the update by simply passing the user ID in the Id field:

 { "MyPersonFieldId": 1 } 

This means that the user must already be in the site collection, so if the user does not exist, the request will fail.

+3
source

The fact is that user information is a search field, so MyPersonField does not exist in your SharePoint list, if you use an OData endpoint, I really donโ€™t know how to save the data, but the same problem arose with me when I tried to read user.

for example {server} / {api} / list / getbytitle ('mylist') / items does not return MyPersonField, but returns MyPersonFieldId,

but if we use

{server} / {api} / list / getbytitle ('mylist') / items /? $ select = *, MyPersonField / Name & $ expand = MyPersonField, we can work with MyPersonField search values

0
source

Use the code below to get the current user ID to save the user in the People and Groups column. The column name of the Requestor user. But to save the user, we must specify the column name as RequestorId

 var userid = _spPageContextInfo.userId; // To get current user ID var itemProperties={'Title':vTitle,'RequestorId':userid}; 
0
source

All Articles