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...
       }) 
    }
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, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.