Forum Discussion
Error 'Cannot get value for projected field...' when users without email were set to the field
SharePoint List Setup
I have a simple list with a Person field Approvers which allows multiple selections. One of the list items has a user set to the Approvers but the said user does not have email configured.
REST API used
https://xxx.sharepoint.com/sites/xxx/_api/Web/Lists(guid'xxx')/items/?$filter=ID eq xxx&$select=*,Approvers%2FEMail&$expand=Approvers
REST API response
Error
{
"odata.error": {
"code": "-2146232832, Microsoft.SharePoint.SPException",
"message": {
"lang": "en-US",
"value": "Cannot get value for projected field Approvers_x005f_EMail."
}
}
}
Graph API used
https://graph.microsoft.com/v1.0/sites/xxx/lists/xxx/items?$filter=startswith(fields/Title, 'xxx')&$expand=fields($select=Title,Approvers)
Graph API response
Success
"Approvers": [
{
"LookupId": 1,
"LookupValue": "User A",
"Email": ""
},
{
"LookupId": 2,
"LookupValue": "User B",
"Email": ""
},
{
"LookupId": 3,
"LookupValue": "User C",
"Email": "******@outlook.com"
}
]
Question
Is there anyway we can tell the REST API to react the same way as Graph API, instead of failing, return the data as-is?
3 Replies
- PankajBadoniIron Contributor
This is a known limitation in the SharePoint REST API. If any user in a Person field (like Approvers) lacks an email, projecting Approvers/EMail will cause the query to fail.
Instead, you can use the Name field to extract the UPN (User Principal Name), which often contains the email. Then, in your code, parse the email from the login name.
items?$filter=Id eq xxx&$select=Id,Title,Approvers/Id,Approvers/Title,Approvers/Name&$expand=Approvers
- ExtenonSpareCopper Contributor
In the SharePoint list settings, assign a display name (instead of the email field) to users without an email address, or manually complete the metadata via PowerShell.
- IvanTiohCopper Contributor
Appreciate the input. Is there anyway I could avoid the error from the API without modifying the SharePoint items?