Using Sharepoint

This is the third and last part of the series: Using MS SharePoint as Data Source. In the earlier posts we learned the basics of SharePoint and the easy way to retrieve data to SharePoint list. In this post we are going to discuss the easiest way of posting data to the SharePoint list.

Posting data to SharePoint can be done in similar way but instead of Query we will use batch element in our CAML.


Batch element provides batch processing of commands within HTTP protocol

  OnError = "Return" | "Continue"
  ListVersion = ""
  Version = ""
  ViewName = "">


To determine the record that needs to be updated, we should use the ID column at SharePoint. ID is a default column at SharePoint list which is auto generated for each record. If you don’t see the field you can enable this at list settings.

Batch element should look like below in your request for posting data. Note that the first field name is the ID which determines which records need to be updated. Consecutive fields are the fields for which value should be updated as passed.


<Batch OnError='Continue' ListVersion='1'>
<Method ID='1' Cmd='Update'>
<Field Name='ID'>1</Field>
<Field Name='Grade'>MD </Field>
<Field Name='Salary'>80000 </Field>


Rest should be straightforward as explained in the last post. Here is a generic function for your reference.


Function PostData(url,splist,spID, spUpdateFeild, spUpdateValue)
PostData = false

batch = "<Batch OnError='Continue' ListVersion='1'>"
batch = batch + " <Method ID='1' Cmd='Update'>"
batch = batch + "  <Field Name='ID'>" & spID & "</Field>"
batch = batch + "  <Field Name='" & spUpdateFeild & "'>" & spUpdateValue & " </Field>"
batch = batch + " </Method>"
batch = batch + "</Batch>"

request = "<?xml version='1.0' encoding='utf-8'?>" & _
"<soap:Envelope xmlns:xsi=''xmlns:xsd=''xmlns:soap=''>" & _
"  <soap:Body>" & _
"    <UpdateListItems xmlns=''>" & _
"      <listName>" & splist & "</listName>" + _
"      <updates>" & batch & "</updates>" & _    
"    </UpdateListItems>" & _
"  </soap:Body>" & _

Set oXML = CreateObject("Microsoft.XMLHTTP")
with oXML
  .open "Get", url, False, null, null
  .setRequestHeader "Content-Type", "text/xml; charset=utf-8"
  .setRequestHeader "SOAPAction",""
  .send request
  strResponse = .responseText
end with 
if instr(strResponse,"<ErrorCode>0x00000000</ErrorCode>") then PostDataToSP = True 
End Function


The generic functions provided in this series can be directly used in UFT and TestComplete. Tested on UFT 12.52 and TestComplete 11 with SharePoint 2010 and SharePoint 2013. Hope you enjoyed the series, let us know your feedback/Comments or questions if any.

See also  Using MS SharePoint as data source : Part 1



Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.