0

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?

clientContext.load(collListItem1);
clientContext.load(collListItem2);
...
...
clientContext.load(collListItemN);

1 Answer 1

0

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

var oList = clientContext
    .get_web()
    .get_lists()
    .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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.