Lets say i have a function that has a for loop in it. I need to loop it becouse i have an array that i need to get items dynamically from: newsArray[i].Group.
In the function Success , i will be checking if the user is in the group then it will show a popup for that user.
The executeQueryAsync is not working in a for loop, how can i acchieve this?
function ShowDialog(){
for(var i = 0; i < newsArray.length; i++){
var currentContext = new SP.ClientContext.get_current();
var currentWeb = currentContext.get_web();
var currentUser = currentContext.get_web().get_currentUser();
currentContext.load(currentUser);
var allGroups = currentWeb.get_siteGroups();
currentContext.load(allGroups);
var group = allGroups.getByName(newsArray[i].Group);
currentContext.load(group);
var groupUsers = group.get_users();
currentContext.load(groupUsers);
context.executeQueryAsync(Function.createDelegate(this, success), Function.createDelegate(this, failed));
}
function success(sender,args){
//show a popup if user is in group
}