Resolve user by display name
- This topic has 2 replies, 2 voices, and was last updated 6 years, 5 months ago by .
Viewing 2 reply threads
Viewing 2 reply threads
- You must be logged in to reply to this topic.
Home › Forums › Autocomplete › Resolve user by display name
Tagged: PeoplePicker
Hi Alex and all,
Wondering if someone knows of the way to populate peoplepicker by user’s Display Name. Unfortunately neither email nor Account ID are available.
Not sure what you mean – just use setFieldValue like this:
setFieldValue("Internal_name_of_people_picker", "Display name of user");
This will however NOT work if you have a comma in the user name – then you would have to get the login name like this:
function getUserByTitle(title){
var user = spjs.utility.queryItems({
"listName": "UserInfo",
"query": "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>User, Test</Value></Eq></Where>",
"viewFields": ["ID","Name"]
});
return user.count > 0 ? user.items[0] : null;
}
// Get the user like this:
var user = getUserByTitle("User, Test");
if(user !== null){
setFieldValue("Internal_name_of_people_picker", user.Name);
}
Alexander
Thanks Alex,
In fact, display name has a comma “Daw, A. John”, whereas UserInfo shows name as “John Daw”. I’ll keep digging