Get Items with CAML query {QueryOption} with GetListItems web Service SharePoint
It took me a while fixing the issues with when I was trying to use CAML Query to Retrieve items using GetListitems SharePoint web service. For that reason, I am posting the whole script here. You can add it to CEWP and test. Works for Announcements list.
<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</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: GetListItemsComplete,
contentType: "text/xml; charset=\"utf-8\""
});
}
function GetListItemsComplete(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>
<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</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: GetListItemsComplete,
contentType: "text/xml; charset=\"utf-8\""
});
}
function GetListItemsComplete(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>
0 comments:
Post a Comment