Add SharePoint List Items using Batching & SP Editor Chrome Extension

Ahamed Fazil Buhari
 
Senior Developer
April 19, 2020
 
Rate this article
 
Views
1830

When we want to fix something quickly then using SP Editor chrome extension gives an oppotunity to run JS script from your browser in Developer Tool.

speditor

 

paste the following script to add items to SharePoint list using batching and hit CTRL+D to run the script

import { sp } from "@pnp/sp/presets/all";
(async () => {
  console.clear();
  let list = sp.web.lists.getByTitle("Large");
  const entityTypeFullName = await list.getListItemEntityTypeFullName();
  let batch = sp.web.createBatch();

  const totalItems = 6000;
  for (var i = 1; i < totalItems; i++) {
    console.log(`Adding Batching for Item ${i}`);
    list.items.inBatch(batch).add({ Title: `Item ${i}` }, entityTypeFullName);

    if(i % 100 === 0) {
        console.log(`Executing Batch for 100 Items`);
        await batch.execute();
        batch = sp.web.createBatch();
    }
  }
})().catch(console.log)

logg

In the console window you can see the item being added using batching.

Happy Coding
Fazil

Author Info

Ahamed Fazil Buhari
 
Senior Developer
 
Rate this article
 
Ahamed is a Senior Developer and he has very good experience in the field of Microsoft Technologies, especially SharePoint, Azure, M365, SPFx, .NET and client side scripting - JavaScript, TypeScript, ...read more
 

Leave a comment