In general, if we want to send multiple queries to SharePoint, we use a batch statement like below.
If I want to filter multiple lists with the below queries in page load/any other events.
  1. Loading all lists available in the site.
  2. Check available of list “XYZ”
  3. Employee list whose department is “IT”
  4. Retrieving regional settings information.
Generally, we will follow the following way.
The above code will work and give the expected result, but here, if the number of batch operations increases, the code itself will be odd to read (if we consider reusability of the code as developer’s main goal).


Here, we need to think about the usage of For loops in this scenario. So, we require an array/object for looping all the queries, if we consider the below portion of code as an array object.

Code Implementation Process

If I want to retrieve data from a SharePoint list (single query) based on the implemented code, I will follow the below process.
In SP-PnP-JS, web is an object of O365 Web(pnp.sp.web). This object has lists property and it is an object of Lists class(pnp.sp.web.lists). This lists property has a method named getByTitle(pnp.sp.web.lists.getByTitle(“XYZ”)) which accepts list name as a parameter and which will return the slected list as List class Object. This List Class has property named items which will return Items class object(pnp.sp.web.lists.getByTitle(“XYZ”).items) . This Items class is extending SharePointQuerable class (so all methods in this are internally used for our original items class) which has get method which will return our data.
Based on the above process of execution and based on JavaScript object feasibility, I thought if we form these all into one array object, which will have information about our query chaining. So, I have just followed the below way of approach to achieve our requirement.
For getting data in a SharePoint List (single query), we need to follow the below steps for forming input array object for reusable method.
  1. By default, we need to create SharePoint Web object (for any kind of GET operations we need to have this is a basic object)
  2. With the help above web object, our next goal to access lists property which will return an object Lists class, so I have used this is my first string in the array.
  3. Based on above Lists class, it has method getByTitle() which accepts list name as a parameter and returns selected list, so it needs two parameters under one array index so we can use this as key-value pair and push it to our above batchLoadQueries array and our array will be as below.
  4. Based on the above query, we are navigated up to lists, so we need to retrieve the items of the list. It is the single property that doesn’t need any kind of key-value pair. So array will be like below

    Up to the above object, it will return items, If it has any kind query/select and these two are key-value pairs so we need to form array as below
If we want to send multiple batch statements, we need to form array of array objects.
Reusable Method(Complete Code please download from attachment)