0

I need to store all the properties for all the users in an array. How can I achieve this, with the executequeryasync method inside my foreach loop?

      var profileProperties = [];
       $(userProfilesArr).each(function(index, userAccount){
            loadUserProfileProperties(userAccount)
       })
       console.log(userProfilePropArray);

    function loadUserProfileProp(userAccount){

      var userProfileProperty = new SP.UserProfiles.UserProfilePropertiesForUser(ctx, userAccount, ["property1","property2"]);
       userProfileProperty = new SP.UserProfiles.PeopleManager(ctx).getUserProfilePropertiesFor(userProfileProperty);
       ctx.load(userProfileProperty);
       ctx.executeQueryAsync(function(){
          //profileProperties.push...
       }) 
    }

1 Answer 1

0

Try by removing the foreach function - sample below:

var profileProperties = [];
       var i=0;
       loadUserProfileProp(userProfilesArr[i]);



    function loadUserProfileProp(userAccount){

      var userProfileProperty = new SP.UserProfiles.UserProfilePropertiesForUser(ctx, userAccount, ["property1","property2"]);
       userProfileProperty = new SP.UserProfiles.PeopleManager(ctx).getUserProfilePropertiesFor(userProfileProperty);
       ctx.load(userProfileProperty);
       ctx.executeQueryAsync(function(){
          //profileProperties.push...
          if(i<=userProfilesArr.length-1){
              i=i+1;
              loadUserProfileProp(userProfilesArr[i]);
          }
          else{
              console.log(userProfilePropArray);

          }
       }) 
    } 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.