I’ve been stuck on an issue for a while trying to retrieve the value of a User field using the SharePoint 2013 REST API.
The MSDN documentation is less than helpful and offers this advice for retrieving the value of lookup fields using REST –
In addition, you can specify that the request returns projected fields from other lists and the values of lookups. To do this, specify the field name in both the $select and $expand query options. For example:
It seems less than clear to me what you need to specify in the $select and $expand parameters!
Doing a bit of googling turned up nothing, surely someone has worked with the REST API in SharePoint 2013?!
If you simply select all fields from the list in your REST query you will find that your field does come back but instead the name will have ‘Id’ appended to it e.g ‘fieldnameId’ and it’s value will be the users’ id in the User Information List.
So what’s the fix I hear you cry?? Well it turns out this is the syntax you need to use in your REST query:
- MyUserField is the name of my User field and Name is the target field in the User Information List. This syntax basically tells the OData property to expand the results for MyUserField to include the value of the Name field.
The User Field will come back as a new object which you can interrogate and there you will see the Name property.
Hope this helps!