2

My goal is to set a Person or Group field value on a new record to a user who may not have logged into the subsite "mysite" (and does not exist at endpoint #2 below), but who does exist at root endpoint, #1 below.

For example, John Smith exists with Id 23 at /sites/_api/web/siteusers, but he does not exist at all at /sites/mysite/_api/web/siteusers. I want to store John Smith in a Person or Group field in a list located in /mysite. John Smith has no Id for that site, however, hence the question.

I'm working with the SharePoint Online REST API using endpoints similar to these:

1 - tenant.sharepoint.com/sites/_api/web/siteusers

2 - tenant.sharepoint.com/sites/mysite/_api/web/siteusers

3 - tenant.sharepoint.com/sites/mysite/_api/web/lists/GetByTitle('MyList')/items

I don't think it is relevant, but the context is a custom web part built with the SharePoint Framework. The web part will be hosted on a modern page within /sites/mysite and is being tested on the tenant workbench (not local) with support files being served from my local machine.

3

If you want a reference to a SP.User stored on a SP.ListItem the user must exist in the SP.UserCollection siteusers of the specific SP.Web (i.e. tenant.sharepoint.com/sites/web/subweb/_api/web/siteusers).

The reason for this is that only the local reference to the Id in the siteusers-list is stored when a user is referenced (using a SP.FieldLookup).

So you'll need to ensure the user exists on the corresponging SP.Web. This is done using the InsureUser-Method of the SP.Web. I.e. by sending the correct POST request to http://<site url>/_api/web/ensureuser

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.