0

Environment : Office 365 Enterprise E3 / SharePoint Online (Plan 2)

To re-create issue : Create a simple list with single line text (named EmployeeName) and people picker column (named EmployeeCode). Now add a list item with completely new EmployeeCode i.e. add user which you have never used/added previously.
And now get the list items using below REST api : /_api/Web/Lists/GetByTitle('MyTestList')/Items?$select=*,EmployeeCode/FirstName,EmployeeCode/LastName&$expand=EmployeeCode

Issue : In response i am getting null values for FirstName and LastName. And it gets resolved after few minutes. Then again if i add new random user, his/her FirstName, LastName will be fetched after few minutes (Same scenario is not seen when i query previous added users). I not sure if this has to do with number of SharePoint users.

Number of SharePoint AD users : 300K+

0

Try using:

/_api/Web/Lists/GetByTitle('MyTestList')/Items?$select=*,Employee/FirstName,Employee/LastName&$expand=Employee

When you use expand, you need call the internal name of the lookup and then select the properties.

EmployeeId is generated to show only the ID of the lookup item and you cannot navigate into the properties using it.

  • We are doing the same thing. It is just that you created people picker column with title Employee and I created column with title EmployeeId. – Sid Dec 14 '17 at 14:02
0

as you say i created a list and add two column there with EmployeeName,EmployeeID this issue is not coming ,while i am using this rest API _spPageContextInfo.webAbsoluteUrl+"/_api/Web/Lists/GetByTitle('TestList')/Items?$top=5000"

this will return a Employee ID in a string and integer format. you need to again pass this id to another rest service to get appropriate user.

As per my knowledge there is no way to get directly username by using one rest Call

0

I was able to figure out why rest query returned null response for a newly added random user. The answer can be found inside User Information list in SharePoint.
What is user information list : User Information List is a special one but still is a list and is bound to the web scope. So it is stored only in the root web of each site collection and you wouldn't find it in any sub-web.
When user is added to this list : When we grant any user permissions to a user or we add any user inside people picker column in the list or user should access the site, they are added automatically to the hidden User Information list a new item will be created in the User Information List storing some information about the user.
How user information is fetched from SharePoint user profile service : There are 2 timer jobs responsible for fetching user information from user profile service. And they are Profile Synchronization (Scheduled : Once every hour) and the Quick Profile Synchronization (Scheduled : Couple of minutes and incremental).
Hence when we add a completely new user inside people picker column and when we try to get user information (in our case it was first name and last name) it returns null value for couple of minutes. In background SharePoint timer job will sync user information list with user profile properties.
Learning : When we try to fetch user inormation using $select and $expand it is actually retrieved from user information list which is located at site level and not from user profile.

Reference : https://gallery.technet.microsoft.com/office/User-Information-List-in-8b420e8c#content

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.