is it possible to get item ids when not using executeQueryAsync. See my code below. I would like to get the item ids as i'm doing below in successGetListItemId() but would like to store in an array and use it later to update some item fields.
Is this possible and if not what are my options?
Thanks in advance
<script language="javascript" type="text/javascript">
///Can't get the itemIDs here
var IDs = [];
var arrayLength = IDs.length;
for (var i = 0; i < arrayLength; i++) {
alert(IDs[i]);
//Want to do an update here :(
}
$(document).ready(function () {
ExecuteOrDelayUntilScriptLoaded(GetListItemId, "sp.js");
});
function GetListItemId() {
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle('Test');
var query = SP.CamlQuery.createAllItemsQuery();
allItems = list.getItems(query);
context.load(allItems);
context.executeQueryAsync(Function.createDelegate(this, this.successGetListItemId));
}
function successGetListItemId() {
var TextFiled = "";
var ListEnumerator = this.allItems.getEnumerator();
while (ListEnumerator.moveNext()) {
var currentItem = ListEnumerator.get_current();
TextFiled += currentItem.get_item('ID');
IDs.push(currentItem);
}
//alert(TextFiled);
$('#ids').append(TextFiled);
console.log(IDs);
}
</script>
<div id="ids"></div>