我正在使用 JSOM 在 SP 2013 Online 中处理 SharePoint 托管应用程序。我的要求是使用电子邮件 ID 获取用户个人资料属性。我知道我们可以使用输入作为帐户名来获取任何用户配置文件,例如
userProfileProperty = peopleManager.getUserProfilePropertyFor(accountName, propertyName)
但是是否可以使用用户的电子邮件 ID 来做同样的事情?
我正在使用 JSOM 在 SP 2013 Online 中处理 SharePoint 托管应用程序。我的要求是使用电子邮件 ID 获取用户个人资料属性。我知道我们可以使用输入作为帐户名来获取任何用户配置文件,例如
userProfileProperty = peopleManager.getUserProfilePropertyFor(accountName, propertyName)
但是是否可以使用用户的电子邮件 ID 来做同样的事情?
SP.UserProfiles.PeopleManager.getUserProfilePropertyFor方法需要accountName
以声明格式提供参数
SharePoint 2013 和 SharePoint 2010 使用以下编码格式显示身份声明:
<IdentityClaim>:0<ClaimType><ClaimValueType><AuthMode>|<OriginalIssuer (optional)>|<ClaimValue>
按照这篇文章进行解释。
对于 SharePoint Online (SPO),帐户使用以下格式:
i:0#.f|membership|username@tenant.onmicrosoft.com
声明可以从电子邮件地址构建:
function toClaim(email)
{
return String.format('i:0#.f|membership|{0}',email);
}
var email = 'username@tenant.onmicrosoft.com';
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);
}
用法
getUserProfilePropertyFor(accountName,profilePropertyName,
function(property){
console.log(property.get_value());
},
function(sender,args){
console.log(args.get_message());
});