0

I want to update the Person or Group field in Document Library using REST API. How can I achieve this.

Thanks.

3

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

  • 1
    This doesn't help to user's question. What would be the way to update the "person" field of certain item, using REST POST. Taking a look to the REST GET json returned, person field is returned as some SP internet ID number – Alberto Dec 18 '17 at 15:40
1

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:

  • If you query the SP USER ID to a different site, you will get a wrong ID number. You need to do this query to the same site where you are uploading your items.
  • Sometimes the request user will not be found in the target site, even though the user has access. In order to get its SPuser id for that current site, you will need to perform the ensureUser web method. Actually, I would recommend to always perform the ensureUser for getting the userId.

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.