How to execute 'n' number of CAML queries to get a different list of objects? We can use multiple clientContext.load() if we have a defined number of queries like clientContext.load(collListItem); clientContext.load(collListItem1);

In my scenario, the queries are generated and cannot determine the number of CAML queries needs to be executed. Is this possible?


I have used window keyword to create dynamic variables to achieve the above scenario.

var oList = clientContext
    .getByTitle("List Name");
  for (index = 0, i = 1; some_valid _condition; index++, i++) {
    window["camlQuery" + i] = new SP.CamlQuery();
    window["camlQuery" + i].set_viewXml("<View><Query><Where><Eq><FieldRef Name='ParentId1' /><Value Type='Text'>" + parentID[index] + "</Value></Eq></Where></Query></View>"); //A sample CAML Query
    this.window["collListItem" + i] = oList.getItems(window["camlQuery" + i]);
    clientContext.load(window["collListItem" + i]);

This is tested and working fine for me.

| improve this answer | |

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.