In the example below, the first alert will print whereas the second one will not. I need to use ctx.executeQueryAsync
to perform a number of operations, but I need to use the updated value of "titles" after this is ran. If I try it afterwards, the console says that "titles" is undefined or blank. I have been able to update variables in for loops throughout the rest of the code, and this is the remaining piece.
This is being used on a SharePoint list by the way.
function doStuff() {
var titles = [];
for(var i = 0; i < selectedItems.length; i++) {
var id = selectedItems[i].id;
var item = list.getItemById(id);
items.push(item);
ctx.load(item, "Title");
}
if (items) {
ctx.executeQueryAsync(function() {
for(var j = 0; j < items.length; j++) {
titles.push(items[j].get_item("Title"));
}
alert(titles.toString());
}, function(sender, args){
alert('Request failed. '
+ args.get_message() + '\n'
+ args.get_stackTrace());
});
}
alert('titles '+titles.toString());
}