Bulk update SharePoint list items programmatically jsom

This SharePoint tutorial, we will discuss how to bulk update sharepoint list items programmatically jsom. The same code we can use to do bulk update list items using JavaScript in SharePoint 2013/2016 or SharePoint Online.

Bulk update SharePoint list items programmatically jsom

Recently we got a requirement to update the status in bulk, like if the user selected 4 items from the SharePoint list and click on Update, then the Status should change to a particular value at a time.

Put the below code inside a script editor web part in the list page basically in the all items view page, where we will have the checkbox to select multiple items.

Once the user selected we will be able to identify which items have been checked by using the below code:

var selectedItems = SP.ListOperation.Selection.getSelectedItems(context);

And then we will update the status.

<input type="button" id="btnUpdate" value="Update Item Status" onclick="UpdateItemStatus();" />

<script>
function UpdateItemStatus()
{
var context = SP.ClientContext.get_current();
var selectedItems = SP.ListOperation.Selection.getSelectedItems(context);
var list = context.get_web().get_lists().getByTitle("MyTestList");
var item;
for (item in selectedItems)
{
var mySelItem = list.getItemById(selectedItems[item].id);
mySelItem.set_item("Status","Approved");
mySelItem.update();
context.executeQueryAsync(Function.createDelegate(this, this.onSucceeded), Function.createDelegate(this, this.onFailed));
}
}

function onSucceeded() {
alert('Items Get updated!');
}

function onFailed(sender, args) {
alert('Some error occured');
}
</script>

You may like following SharePoint jsom tutorials:

This SharePoint JSOM tutorial, we learned how to update bulk items using javascript in SharePoint Online or SharePoint 2013/2016/2019.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>