Updating URL field using Lists.asmx


Updating URL field using SharePoint Lists Web Service (Lists.asmx)

One thing that I always complain about SharePoint 2007 web service is lack of documentation and samples.  This is the most neglected areas of SharePoint 2007.  I hope this have been improved in SharePoint 2010 especially since Microsoft has added a lot of new web services.

I had been working on a jQuery based SharePoint solution to display a modal popup to all the visitors. Apart from displaying the jQuery pop up dialogue on page load, I also had to record the history about visitor.

I had to update the list items using Lists.asmx UpdateListItems() method. 

My custom list had following fields:-

Field Name
Type
Description
Title
Text
This field is used to record the login name of logged in user
URL
URL
This field is used to store the link of a text file hosted on server.

After struggling for some time I found that updating the URL field requires some additional attention, since the SharePoint URL field value consists of two parts <URL>, <Description>. Even when working with Object Modal we have to use SPUrlFieldValue.

Please make sure to follow these guidelines while updating the URL field through web services.

          Please notice that URL needs to include “http://” e.g. http://www.google.com/, generally we write http://www.google.com/ and think that SharePoint should be intelligent enough to append http, but this is not the case.

          The other thing is that we need to make sure to include a space between the comma (,) and description.  So our URL field value needs to have <URL including http://&gt;,<SPACE><Description>, e.g. http://www.google.com/, Google.

Please pay extra attention while updating/Reading the URL field (through Web Service or thorough object modal).

Here is how the element should look in your soap envelope.

<Field Name=”URL”>http:\\www.google.com, Google</Field>

Here is my soap envelop for calling the UpdateListItems() method. I have omitted the other parts of calling the web service for clarity. (You get lots of examples through Google)
                // The SOAP Envelope
var soapEnv =
“<?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> \
                <UpdateListItems xmlns=\”http://schemas.microsoft.com/sharepoint/soap/\”> \
                <listName>Audit</listName> \
 <updates> \
<Batch OnError=\”Continue\”> \

                                                                                <Method ID=\”1\” Cmd=\”New\”> \

                                                                                                <Field Name=\”Title\”>Some Text</Field> \

<Field Name=\”URL\”>http://www.google.com, Google</Field> \

                                                                                </Method> \

</Batch>

                </updates> \
                </UpdateListItems> \
                  </soap:Body> \
                </soap:Envelope>”;

Hope this helps someone in need J

Regards,
Sudhir Kesharwani 
MCTS – MOSS 2007 | MCTS – WSS 3.0 | MCPD-EA | MCSD.NET 
Advertisements

One thought on “Updating URL field using Lists.asmx

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s