Working with SharePoint Web Services + JQuery to Add, Update and Delete items in SharePoint list

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.

Some of the Important examples that I will discuss in this series of blog posts are

How to Retrieve Items using Getlistitems with CAML query

How to Add\Delete\Update a single item using UpdatelistItems Web Service

How  to batch update items using UpdatelistItems Web Service based on a CAML query

How to batch Delete using UpdatelistItems Web Service based on a CAML query

Firstly,  Lets look at  how to Retrieve Items using Getlistitems with CAML query (with QueryOptions). We will use Announcements list as an example.

How to Retrieve Items using Getlistitems with CAML query -  The below code retrieves all the Announcements from the Announcement list where   Title = “Test Announcement” . You can paste the below code in a Content Editor WebPart for Testing Purposes. You would click on “Get Announcements” link in your CEWP to display resulting Announcements on the page.

<script  type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script type="text/javascript">

function GetAnnouncements(){

var soapEnv = "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
<soap:Body> \
<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
<listName>Announcements</listName> \
<query><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>Test Announcement</Value></Eq></Where></Query></query> \
<viewFields> \
<ViewFields> \
<FieldRef Name='Title' /> \
<FieldRef Name='Body' /> \
<FieldRef Name='Expires' /> \
</ViewFields> \
</viewFields> \
<rowLimit>99999</rowLimit> \
<queryOptions xmlns:SOAPSDK9='http://schemas.microsoft.com/sharepoint/soap/' ><QueryOptions/> \
</queryOptions> \
</GetListItems> \
</soap:Body> \
</soap:Envelope>";
jQuery.ajax({
url: "/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: ProcessListItems,
contentType: "text/xml; charset=\"utf-8\""
});
}

function ProcessListItems(xData, status) {

jQuery(xData.responseXML).find("z\\:row").each(function () {
alert($(this).attr("ows_Title"));
$("<li>" + $(this).attr("ows_Title") + "</li>").appendTo("#Announcements");

});

}
</script>

<a href="#" onclick="Javascript:GetAnnouncements();">Get Announcements</a>

<ul id="Announcements"></ul>

Next lets look at how to use UpdatelistItems  Web service toAdd\Delete\Update a single item using UpdatelistItems Web Service and perform bulk updates.

4 Responses to “Working with SharePoint Web Services + JQuery to Add, Update and Delete items in SharePoint list”

  1. Chantal July 13, 2012 at 11:26 pm # Reply

    Sharepoint’s collaboration feraetus are valuable for any company, but the BI (Enterprise only) feraetus are the real reason to bother with the huge paradigm shift in the first place. Sharepoint is the future of the Microsoft platform and should, IMHO, be embraced, because they are really putting out cost effective and useful tools that will make a company work not harder, but smarter.

Trackbacks/Pingbacks

  1. How to AddDeleteUpdate Items using UpdatelistItems Web Service in SharePoint | Akrura Technologies - May 24, 2012

    [...] the Previous post you saw an example of  How to Retrieve Items using Getlistitems with CAML query. In Continuation with the series next we will see the about How to AddDeleteUpdate Items using [...]

  2. Batch update items with UpdatelistItems Web Service + JQuery based on a CAML query | Akrura Technologies - May 24, 2012

    [...] Continuation with the Blog series about Working with SharePoint Web Services + JQuery to Add, Update and Delete items in SharePoint list In this post we will see how to batch update items using UpdatelistItems Web Service and JQuery [...]

  3. Batch delete items with UpdatelistItems SharePoint Web Service + JQuery with CAML query | Akrura Technologies - May 24, 2012

    [...] Continuation with the Blog series about Working with SharePoint Web Services + JQuery to Add, Update and Delete items in SharePoint list In this post we will see how to batch update items using UpdatelistItems Web Service and JQuery [...]

Leave a Reply