SharePoint userProfileProperties JSOM(JavaScript对象模型)
我正在尝试从PeopleManager.getMyProperties()函数获取一些信息。 当我从管理层的用户配置文件中检查对象时,我可以看到值。我该怎么修这个 这是获取对象的工作代码。SharePoint userProfileProperties JSOM(JavaScript对象模型),sharepoint,sharepoint-2013,javascript-objects,sharepoint-jsom,Sharepoint,Sharepoint 2013,Javascript Objects,Sharepoint Jsom,我正在尝试从PeopleManager.getMyProperties()函数获取一些信息。 当我从管理层的用户配置文件中检查对象时,我可以看到值。我该怎么修这个 这是获取对象的工作代码。 注意:我想从我以前创建的用户配置文件访问自定义属性。 我可以看到对象中的属性,但没有值 谢谢大家 $(document).ready(function(){ SP.SOD.executeOrDelayUntilScriptLoaded(loadUserData, 'SP.User
注意:我想从我以前创建的用户配置文件访问自定义属性。 我可以看到对象中的属性,但没有值 谢谢大家
$(document).ready(function(){
SP.SOD.executeOrDelayUntilScriptLoaded(loadUserData, 'SP.UserProfiles.js');
});
var userProfileProperties;
function loadUserData(){
//Get Current Context
var clientContext = new SP.ClientContext.get_current();
//Get Instance of People Manager Class
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
//Get properties of the current user
userProfileProperties = peopleManager.getMyProperties();
clientContext.load(userProfileProperties);
//Execute the Query.
clientContext.executeQueryAsync(onSuccess, onFail);
}
function onSuccess() {
console.log(userProfileProperties)
}
function onFail(sender, args) {
console.log("Error: " + args.get_message());
}
试试下面的代码,让我知道。这对我来说很好。我传递的是用户名而不是我的帐户。这样您就可以在这里传递任何用户帐户
function getUserProperties(userName) {
var clientContext = new SP.ClientContext.get_current();
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
var profilePropertyNames = ["FirstName", "LastName", "CustomProperty"]; //Have to load all the needed properties here
var targetUser = userName.trim();
var userProfilePropertiesForUser = new SP.UserProfiles.UserProfilePropertiesForUser(clientContext, targetUser, profilePropertyNames);
userProfileProperties = peopleManager.getUserProfilePropertiesFor(userProfilePropertiesForUser);
clientContext.load(userProfilePropertiesForUser);
clientContext.executeQueryAsync(onSuccess, onFail);
}
function onSuccess() {
// userProfileProperties result index is same as the properties loaded above
var firstName=userProfileProperties[0];
var lastName=userProfileProperties[1];
var customprop=userProfileProperties[2];
}
如果有帮助,请将其标记为答案。我忘了写解决方案,很抱歉 我尝试了@NaveenPrasath编写的代码。它提供了很多字段,但没有返回“自定义道具字段” 工作代码如下所示
function getUserProperties(targetUser) {
var clientContext = new SP.ClientContext.get_current();
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
personProperties = peopleManager.getPropertiesFor(targetUser);
clientContext.load(personProperties);
clientContext.executeQueryAsync(onRequestSuccess, onRequestFail);
}
function onRequestSuccess() {
var fullName = personProperties.get_userProfileProperties()['CustomPropField'];
}
我尝试了代码,我得到了属性,但自定义属性仍然为空。感谢“用户名”建议和帮助。我会找的,等你找到的时候,我会告诉你的@纳文普拉萨