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());
});
参考文献
SharePoint 2013: Claims Encoding