More on VBScript and SharePoint SOAP

  • : Function split() is deprecated in /hsphere/local/home/guruj/guruj.net/modules/filter/filter.module on line 1200.
  • : Function split() is deprecated in /hsphere/local/home/guruj/guruj.net/modules/filter/filter.module on line 1200.

In response to a question from a reader, Tim, this is a follow-up from an earlier article on SharePoint, SOAP and VBScript. This time, we'll look at how to do more complex calls to SharePoint web services in VBScript

Some web services in SharePoint require passing XML as parameters. Unfortunately, you can't pass an XML document, it has to be an XML node element, and this takes a bit of effort to construct in VBScript.

The example we'll use is making a call to GetListItems, which returns all items in a SharePoint library, optionally matching a query formatted using a special XML syntax.

To correctly call this web service, create a VBScript file with the following lines:

Dim xmlDoc, SOAPClient

Set xmlDoc = CreateObject("MSXML2.DOMDocument.5.0")
xmlDoc.async = False
xmlDoc.loadXML( _
   "<Document>" + _
   "  <Query><Where><Gt><FieldRef Name=""ID"" />" + "<Value 
Type=""Counter"">1</Value></Gt></Where></Query>" + _
   "  <ViewFields/>" + _
   "  <QueryOptions/>" + _
   "</Document>")

Set SOAPClient = CreateObject("MSSOAP.SOAPClient")
SOAPClient.mssoapinit 
"http://sharepoint.alentus.com/_vti_bin/Lists.asmx?WSDL"

Dim result
Set result = SOAPClient.GetListItems( "Tasks", "", _
   xmlDoc.getElementsByTagName("Query"), _
   xmlDoc.getElementsByTagName("ViewFields"), "", _
   xmlDoc.getElementsByTagName("QueryOptions"), "" )

DisplayNode result.childNodes

There are a number of ways to create and retrieve XML nodes, of course, but this way has the benefit of being fairly concise and self-explanatory.

Comments

Error with GetListItems

Hi,

Great to find this and the other page. However, while the other page retrieves the views this example errors out on SOAPClient.GetListItems. The error I get from VBScript is:-

VBScript runtime error: Invalid procedure call or argument: 'SOAPClient.GetListItems'

Hugh