2

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

Thanks.

1

2 Answers 2

4

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
  • 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 S.
    Commented Dec 18, 2017 at 15:40
2

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.
2
  • Alberto - On your second point on Notes: Can't we get the SP USER ID by allowing the entire site access to all. I mean Open access to all. I have more than 500 unique users to update in one of the SP list (Having 6000 records) person or group field. Kindly suggest. Is there any other alternative solution available to update person or group field in SP list? Commented Aug 29, 2020 at 11:25
  • Either you 1) use the ensureUser approach for each user, let’s say, 500users. With those userId, you modify those 6000 records. 2) you change the permisión on the library for those users, and then all records in library use same permission. 3) you create a userGroup with those users, and you just continue work with that group 4) you put the records on a folder and modify permission for that folder
    – Alberto S.
    Commented Aug 29, 2020 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.