2

I need to load all master data from multiple lists and bind it to from in form dropdown. For that I need to call every list separately. Is there any option to call all the list in one query using REST api batch.? I tried to search but Batch requests are available only for Add,Update and Delete. Please help..!

0

The simplest way is to use PnPJS library for that purpose. $batch itself is a bit complicated when it comes to response parsing, etc. however PnPJS library hides all complicated logic inside.
This is how you can query multiple lists in one HTTP request with PnPJS:

import { sp } from "@pnp/sp";

const batch = sp.web.createBatch();

sp.web.getList("sites/<your site>/Lists/List1").items.inBatch(batch).get()
.then(items1 => {
    console.log(items1);

});
sp.web.getList("sites/<your site>/Lists/List2").items.inBatch(batch).get()
.then(items2 => {
    console.log(items2);

});;

// this line executes actual HTTP request to $batch endpoint
batch.execute()
.then(data => {
    // at this point all requests will be completed
    console.log('done');
});
  1. I recommend you to install Chrome SP Editor add-in.
  2. Then open your SharePoint site with targeted lists.
  3. Then Open developer tools.
  4. Go to the SharePoint tab and select PnPJS console in the left menu.
  5. Copy\Paste my code (don't forget to fix urls) and hit CTRL+D.
  6. In a console you will see the result.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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