【问题标题】:SharePoint userProfileProperties JSOM (JavaScript Object Model)SharePoint userProfileProperties JSOM(JavaScript 对象模型)
【发布时间】:2017-09-20 16:39:26
【问题描述】:

我正在尝试从 PeopleManager.getMyProperties() 函数中获取一些信息。 我得到了对象,有些值为空。当我从管理的用户配置文件中检查它时,我可以看到该值。我该如何解决这个问题?

有我的工作代码来获取对象。
注意:我想从我之前创建的 User Profile访问自定义属性。 我可以看到对象中的属性,但值没有出现。

谢谢大家..

  $(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());
  } 

【问题讨论】:

    标签: sharepoint sharepoint-2013 javascript-objects sharepoint-jsom


    【解决方案1】:

    试试下面的代码,让我知道。这对我来说可以。我传递的是用户名而不是我的帐户。这样您就可以在此处传递任何用户帐户。

        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
    【解决方案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'];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-18
      • 2020-11-17
      • 1970-01-01
      相关资源
      最近更新 更多