Update or Delete SharePoint 2010 List Item using Javascript Object Model

InfoPath alternatives for form designing SharePoint

In this blog post I will entirely focus on Getting List items, Updating List items and Deleting List items using SharePoint Web Services. The code uses Jquery to Retrieve items and makes an ajax call to SharePoint Web Services. In this script, I have Update /Delete method and UpdateListem/deleteListItems method

If you want to learn SharePoint online then you can Download a FREE PDF on SharePoint online tutorial and Download FREE PDF on HUB site in SharePoint online.

Update SharePoint List item using jsom (javascript object model):

<script type=”text/javascript”>
function update()
{
var UpdateNewItemXml= “<Batch OnError=’Continue’ ListVersion=’1′>”

+ “<Method ID=\”1\” Cmd=\”Update\”>”
+ “<Field Name=’ID’>2</Field>”
+ “<Field Name=’Name’>Mack</Field>”
+ “</Method>”
+ “</Batch>”;

FeedbackHTTP = new ActiveXObject(“MSXML2.XMLHTTP.3.0”);
FeedbackHTTP.Open(“POST”, “http://spsrvr:800/sites/test/_vti_bin/lists.asmx”, false);
FeedbackHTTP.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);
FeedbackHTTP.setRequestHeader(“SOAPAction”,”http://schemas.microsoft.com/sharepoint/soap/UpdateListItems”);

var strSOAP = “<?xml version=\”1.0\” encoding=\”utf-8\”?>”
+”<soap:Envelopexmlns:xsi=\”http://www.w3.org/2001/XMLSchemainstance\”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>MyList</listName>”

+ “<updates>”+ UpdateNewItemXml + “</updates>”

+ “</UpdateListItems>”

+ “</soap:Body>”

+ “</soap:Envelope>”;

FeedbackHTTP.Send(strSOAP);

alert(“Thank you! your suggestion has been Updated successfully.”);

}
</script>

Delete SharePoint List item using jsom (javascript object model):

<script type=”text/javascript”>
function Delete ()
{
var UpdateNewItemXml= “<Batch OnError=’Continue’ ListVersion=’1′>”

+ “<Method ID=\”1\” Cmd=\”Delete\”>”

+ “<Field Name=’ID’>2</Field>”
+ “<Field Name=’Name’>Mack</Field>”

+ “</Method>”

+ “</Batch>”;
FeedbackHTTP = new ActiveXObject(“MSXML2.XMLHTTP.3.0”);
FeedbackHTTP.Open(“POST”, “http://sp2k10srvr:800/sites/test/_vti_bin/lists.asmx”, false);
FeedbackHTTP.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);
FeedbackHTTP.setRequestHeader(“SOAPAction”,”http://schemas.microsoft.com/sharepoint/soap/UpdateListItems”);
var strSOAP = “<?xml version=\”1.0\” encoding=\”utf-8\”?>”
+”<soap:Envelopexmlns:xsi=\”http://www.w3.org/2001/XMLSchemainstance\”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>31stmay</listName>”

+ “<updates>”+ UpdateNewItemXml + “</updates>”

+ “</UpdateListItems>”

+ “</soap:Body>”

+ “</soap:Envelope>”;

FeedbackHTTP.Send(strSOAP);

alert(“Thank you! your suggestion has been Deleted successfully.”);


}

Hope fully this article will helpful to you, to update or delete list items using JavaScript object model (jsom).


You May Also like the Following SharePoint Online Tutorials:

About Sagar Pardeshi

I am Developer working on Microsoft Technologies for the past 6+years. I am very much passionate about programming and my core skills are SharePoint, ASP.NET & C#,Jquery,Javascript,REST. I am running this blog to share my experience & learning with the community I am an MCP, MCTS .NET & Sharepoint 2010, MCPD Sharepoint 2010, and MCSD HTML 5,Sharepoint 2013 Core Solutions. I am currently working on Sharepoint 2010, MOSS 2007, Sharepoint 2013,Sharepoint 2013 App Dev, C#, ASP.NET, and SQL Server 2008.

View all posts by Sagar Pardeshi →

Leave a Reply