Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

SharePoint Rest Api in Batch using PnP JS

import { sp } from "@pnp/sp/presets/all";
import { dateAdd } from "@pnp/common";

const batch = sp.web.createBatch();

var ListsArr = ["Admin_Test", "Test_attch","TestCopy"]
ListsArr.forEach((list)=>{
  sp.web.getList(`sites/MyTeamSite/Lists/${list}`).items.inBatch(batch).usingCaching({
    expiration: dateAdd(new Date(), "minute", 2),
    key: `cache_${list}`,
    storeName: "local"
  }).get()
.then(items1 => {
    console.log(items1);
});
})


// this line executes actual HTTP request to $batch endpoint
batch.execute()
.then(data => {
    // at this point all requests will be completed
    console.log('done');
});
Source by mynotes955000.blogspot.com #
 
PREVIOUS NEXT
Tagged: #SharePoint #Rest #Api #Batch #PnP #JS
ADD COMMENT
Topic
Name
8+7 =