Bulk Update in SharePoint List Items Using JSOM
Softree Technology > Blogs > SharePoint > Bulk Update in SharePoint List Items Using JSOM

Bulk Update in SharePoint List Items Using JSOM

  • Posted by: Softree Technology

In this blog, we will discuss about bulk update in the SharePoint list items. We are going to use JSOM code to perform the above action. Bulk update is very much efficient as any kind of huge changes or update in the list & list items can be done within fraction of second. In this blog, we have updated the items’ Title from “MyItem” to “NewItem” i.e. in the list which item Title is “MyItem” it will be changed to “NewItem”. To Perform this please refer the below steps:

Step 1: First get the Current Context.

Step 2: Get the list by its “Title” in which you want to update the list Items (In this programmed I used the List ‘Testlist’) .

Step 3: To Load the item collection, we used CamlQuery.

Step 4: Declared an ItemArray for bulk update.

Step 5: We retrieved all the items by using enumerator.

Step 6: We updated the bulk items.

Follow the complete code:

function BulkItemUpdate() {
        var itemName = "MyItem";
        var ctx = SP.ClientContext.get_current();
        var oWeb = ctx .get_web();
        var oList = oWeb.get_lists().getByTitle('TestList');
        var camlQuery = new SP.CamlQuery();
        camlQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + itemName + "</Value></Eq></Where></Query></View>");
        
        var itemColl = oList.getItems(camlQuery);
        ctx.load(oWeb);
        ctx.load(oList);
        ctx.load(itemColl);

            ctx.executeQueryAsync(function () {
            var itemArray = [];
            if (itemColl.get_count() > 0) {
                var itemEnum = itemColl.getEnumerator();
                while (itemEnum.moveNext()) {
                    var item = itemEnum.get_current();
                    var itemId = item.get_item("ID");
                    var items = oList.getItemById(itemId);
                    items.set_item("Title", "NewItem");
                    items.update();
                    itemArray.push(items);
                    ctx.load(itemArray[itemArray.length - 1]);
                }
                ctx.executeQueryAsync(function () {
                    alert("Items are updated Successfully");
                }, function (sender, args) {
                    console.log("Request Failed to get TestList Items :" + args.get_message());
                });
            }
        }, function (sender, args) {
            console.log("Request failed in List " + args.get_message());
        });
    }

Before performing these steps, the list view is like below:

After performing the bulk update operation, the list item title is now changed to “NewItem”. Refer below image.

Keywords:

  • How to update bulk in SharePoint List Items Using JSOM
  • Update SharePoint list items in batch using JSOM
  • Updating List items in batch using JSOM

Author: Softree Technology

Leave a Reply