Creating SharePoint list item with vbscript and WebServices

Few days back I had some urgent requirement to create and update a sharepoint list item using vbscript and sharepoint WebServices. After goggling a bit i found a solution in one of the msdn forums .. so posting the code here with my additions

Code :
Sub AddListItem(site, listGUID, itemTitle)
strEndPointURL = "http://moss" + site + "/_vti_bin/Lists.asmx"
strSoapAction="http://schemas.microsoft.com/sharepoint/soap/UpdateListItems"
Set objSOAPConnector = CreateObject("MSOSOAP.HttpConnector30")
with objSOAPConnector
.Property("EndPointURL") = strEndPointURL
.Property("SoapAction") = strSoapAction
.Connect
End With
Set objSOAPSerializer = CreateObject("MSOSoap.SoapSerializer30")
with objSOAPSerializer
.Init(objSOAPConnector.InputStream)
.startEnvelope()
.startBody()
.StartElement "UpdateListItems", "http://schemas.microsoft.com/sharepoint/soap/"
.StartElement "listName", "http://schemas.microsoft.com/sharepoint/soap/"
.WriteString(listGUID)
.EndElement()
.StartElement "updates","http://schemas.microsoft.com/sharepoint/soap/"
.StartElement "Batch"
.SoapAttribute "ListName", ,listGUID
.SoapAttribute "OnError", ,"Continue"
.StartElement "Method"
.SoapAttribute "ID", ,"1"
.SoapAttribute "Cmd", ,"New"
.StartElement "Field"
.SoapAttribute "Name", ,"Title"
.WriteString(itemTitle)
.EndElement()
.EndElement()
.EndElement()
.EndElement()
.EndElement()
.endBody()
.endEnvelope()
End With
objSOAPConnector.EndMessage()
Set objResponseReader = CreateObject("MSOSOAP.SoapReader30")
objResponseReader.Load(objSOAPConnector.OutputStream)
Wscript.echo objResponseReader.Body.xml
End Sub

1 comments:

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer or anyone else. Should you have any questions or concerns please e-mail me at sharepointprogrammingblogger@gmail.com .

Copyright (c) 2010 @ myshaepointwork.blogspot.com. All rights are reserved.Do Not Copy.

@ Learning SharePoint.com