Hello everyone :-)
I'm facing a problem which is, I think, might be answered somewhere but I don't find :(
So, here it is: I want to get my SharePoint groups of my Site Collection, then the users in, finally the details of this users.
That's what I got:
function getCurrentGroups() { this.clientContext = new SP.ClientContext.get_current(); var oWeb = clientContext.get_web(); this.allGroups = oWeb.get_siteGroups(); this.clientContext.load(allGroups); this.clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceededGroups), Function.createDelegate(this, this.onQueryFailedGroups)); } function onQuerySucceededGroups() { var groupsEnum = allGroups.getEnumerator(); while (groupsEnum.moveNext()) { console.log(groupsEnum.get_current().get_title() + " : "); this.allUsers = groupsEnum.get_current().get_users(); this.clientContext.load(allUsers); this.clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySuccedUser), Function.createDelegate(this, this.onQueryFailedUsers)); } } function onQuerySuccedUser() { var usersEnum = allUsers.getEnumerator(); while (usersEnum.moveNext()) { console.log(usersEnum.get_current().get_title()); } } $(document).ready(function() { getCurrentGroups(); })
The biggest problem here, is this line:
this.clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySuccedUser), Function.createDelegate(this, this.onQueryFailedUsers));
Because this line is in a loop and the call is async.
How can I manage to do: when the callback come back, continue the loop? Or doing something totally different, if so, tell me how you achieves this?
Thanks in advance.
Regards,
Mafyou.
Cordialement, Mafyou.