Update List item in batch in SharePoint 2013

InfoPath alternatives for form designing SharePoint

In this post we will discuss how to do batch update in list item in SharePoint 2013. You can check out this article before reading this.

Also check out:

– Custom timer job sharepoint 2010

– How to backup and restore SharePoint 2010 site collection?

– Create Navigation menu 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”);
}

Similar SharePoint 2013 Tutorials


Leave a Reply