Searching a List using List Web Service and Javascript

Hi,

                Some time back, we were trying to do a search on List and show the results in a page. And bcose of the requirement, the default search functionality provided by sharepoint has bcome out of scope. And we don't want to write a custom web part for it, just bcose of installation issues. So, we thought of calling List WebService from JavaScript, parse result and display it. Everything through Content Editor Web Part.

So, what are required to do it from javascript ( SOAP Envelope and AJAX)

Let't see first, how to call the web service from javascript.

var oWebService = new ActiveXObject("Microsoft.XMLHTTP");
oWebService.open("POST", "Web service URL comes here", false);
oWebService.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetListItems");
oWebService.setRequestHeader("Content-Type", "text/xml");
oWebService.send("SOAP envelope");
var responseXML = oWebService.responseText;

Here are the values that we need to pass (Sample values)

Web Service URL
     "http://yoursite/subsite/_vti_bin/Lists.asmx"

SOAP Envelope
<?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><GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>List Name</listName>
<queryOptions></queryOptions>
<query><Query><Where><Eq><FieldRef Name="Title"/><Value Type="Text">Test</Value></Eq></Where></Query></query>
</GetListItems>
</soap:BOdy>
</soap:Envelope>

That's it. For more details on SOAP Envelope look into the list web service. This code might not work in all browsers. Only one function of List Web Service (GetListItems) is used here. This is just a abstract to give a idea. Hope this is useful.

Regards

Satheesh Palaniswamy.

 

 

Leave a Reply