Reputation: 53
I'm working on SharePoint hosted app in SP 2013 Online using JSOM. My requirement is to get user profile properties by using email id. I know that we can get any user profile using input as account name e.g.
userProfileProperty = peopleManager.getUserProfilePropertyFor(accountName, propertyName)
but is it possible to do the same using email id of a user?
Upvotes: 1
Views: 4056
Reputation: 59328
SP.UserProfiles.PeopleManager.getUserProfilePropertyFor method expects accountName
parameter to be provided in claim format
SharePoint 2013 and SharePoint 2010 display identity claims with the following encoding format:
<IdentityClaim>:0<ClaimType><ClaimValueType><AuthMode>|<OriginalIssuer (optional)>|<ClaimValue>
Follow this article for an explanation.
In case of SharePoint Online (SPO) the following format is used for an account:
i:0#.f|membership|[email protected]
The claim could be constructed from email address:
function toClaim(email)
{
return String.format('i:0#.f|membership|{0}',email);
}
var email = '[email protected]';
var profilePropertyName = "PreferredName";
var accountName = toClaim(email);
function getUserProfilePropertyFor(accountName,profilePropertyName,success,failure)
{
var context = SP.ClientContext.get_current();
var peopleManager = new SP.UserProfiles.PeopleManager(context);
var userProfileProperty = peopleManager.getUserProfilePropertyFor(accountName,profilePropertyName);
context.executeQueryAsync(
function(){
success(userProfileProperty);
},
failure);
}
Usage
getUserProfilePropertyFor(accountName,profilePropertyName,
function(property){
console.log(property.get_value());
},
function(sender,args){
console.log(args.get_message());
});
SharePoint 2013: Claims Encoding
Upvotes: 3