Update List item in batch in SharePoint 2013


This SharePoint 2013 tutorial explain, how to do the batch update in list item in SharePoint 2013.

Here is the example:

function BatchUpdate(obj,listname,siteurl) {
var fields = “”;
//here Obj has 2 properties Id and Position and batch Update is done i.e according to id positions are updated in list
for(var i=0;i<obj.length;i++){
fields += “<Method ID=\””+obj[i].Id+”\” Cmd=\”Update\”><Field Name=\”ID\”>” + obj[i].Id+ “</Field><Field Name=\”Position\”>” + obj[i].Position+ “</Field></Method>”;
}
var batch = “<Batch OnError=\”Continue\”>” + fields + “</Batch>”;
var soapEnv = BuildSoapEnv(batch,listname);
UpdateBatchItems(soapEnv, onSuccessUpdate,siteurl);

}

function BuildSoapEnv(batch, listname)
{
var soapEnv =
“<?xml version=\”1.0\” encoding=\”utf-8\”?> \
<soap:Envelope xmlns:xsi=\”http://www.w3.org/2001/XMLSchema-instance\” \
xmlns:xsd=\”http://www.w3.org/2001/XMLSchema\” \
xmlns:soap=\”http://schemas.xmlsoap.org/soap/envelope/\”> \
<soap:Body> \
<UpdateListItems xmlns=\”http://schemas.microsoft.com/sharepoint/soap/\”> \
<listName>” + listname+ “</listName> \
<updates> \
” + batch + “</updates> \
</UpdateListItems> \
</soap:Body> \
</soap:Envelope>”;
return soapEnv;
}

function UpdateBatchItems(soapEnv, functionToCall,siteurl)
{
$.ajax({
url: siteurl+ “/_vti_bin/Lists.asmx”,
beforeSend: function(xhr) {
xhr.setRequestHeader(“SOAPAction”,”http://schemas.microsoft.com/sharepoint/soap/UpdateListItems”);},
type: “POST”,
dataType: “xml”,
crossdomain:true,
data: soapEnv,
complete: functionToCall,
contentType: “text/xml; charset=\”utf-8\””
});
}
function onSuccessUpdate()
{
alert(“Success”);
}


Read SharePoint branding tutorials

Hope this article will be helpful.


You May Also like the Following SharePoint Online Tutorials:

Leave a Reply