I want to update the Person or Group
field in Document Library
using REST API.
How can I achieve this.
Thanks.
To add/update Person or Group
field, you need the Id of Person or Group. Let say, Person or Group Id
is 11
and internal name of the field is PersonField
. So the request will be
var data = {
PersonFieldId: 11
};
PS: Don't forget to add Id
with the field's internal name. I wrote details in my article CRUD Operation to List Using SharePoint 2013 Rest API
You will need to know the Sharepoint user ID for that current site. To do so, you would need to query the following REST request:
http://[your domain]/[your site]/_api/web/siteusers?$filter=substringof('|[your user login]',LoginName) eq true
Where [your user login] would be something like domain\user. Remember also to correctly fill up [your domain] & [your site].
The JSON returned contains a field named Id. You'll need that value for composing the JSON you are going to send to the server endpoint:
data_to_be_sent:
JSON.stringify
({
__metadata:
{
type: data.__metadata.type
},
Title: myTitle,
Employee_x0020_NameId: Id,
})
NOTES: