Showing posts with label spfx pnp batch operation. Show all posts
Showing posts with label spfx pnp batch operation. Show all posts

Sunday, 17 March 2019

Batch Operation using pnp


private BatcOperation():void
{
let batchResults = [];
let batch=pnp.sp.createBatch();
pnp.sp.web.lists.getByTitle("Test").items.inBatch(batch).add({Title:"1"})
.then(function(response){
console.log(1);
batchResults.push(response);
});
pnp.sp.web.lists.getByTitle("Test").items.inBatch(batch).add({Title:"2"})
.then(function(response){
console.log(2);
batchResults.push(response);
});;
pnp.sp.web.lists.getByTitle("Test").items.inBatch(batch).add({Title:"3"})
.then(function(response){
console.log(3);
batchResults.push(response);
});;
pnp.sp.web.lists.getByTitle("Test").items.inBatch(batch).add({Title:"4"})
.then(function(response){
console.log(4);
batchResults.push(response);
});;
batch.execute().then(function(){
console.log("Final");
console.log(batchResults);
}).catch(function(exception){
alert("Something went wrong :"+exception);
});

}