SP2007 UpdateListItems with Hyperlink column

Feb 18, 2013 at 7:45 AM
I have been using SPServices for many months. Terrific library. I have learned lots by just reading the code! Now to the problem.
I have a hyperlink field on a SP2007 list. I am using UpdateListItems with a new cmd. The problem I am having is that SP does not create a link with my update value. I have tried sending HTML, encoded HTML, a plain link, and even the old 'url, url description'. I can create the link on the SP NewForm.aspx page and when read through web services shows up as an HTML anchor. However, feeding the exact same thing back causes sharepoint to just display the anchor as text. Anyone have a pointer for me?
Coordinator
Feb 18, 2013 at 2:42 PM
So is the problem updating a Hyperlink or Picture column with UpdateListItems or just diplaying the link after the update?

M.
Feb 18, 2013 at 10:14 PM
Edited Feb 18, 2013 at 10:29 PM
I have list column that is defined as a hyperlink. I am using a non-sharepoint page to add new items as well as update them. When I add a new record, all is fine excep that the hyperlink is displayed as the anchor text, not the "link". So <a href="http://www.google.com">Google</a> gets shown as plain text,not a link with "Google" displayed. If I manually edit the list item with EditForm.aspx, it displays properly. Retrieving the list item using GetListItems gives me the correct anchor html. I have looked at the post via fiddler and everything seems in order. The one thing I haven't tried is to setup the CAML instead of using value pairs so that I can set the type= in the update. I am unclear whether my request is specified correctly or if some escaping is required. A correctly formated field should yield a link in the DispForm.aspx.

correct format Image

not so correct Image

I have tried the action below with 1) plain url, 2) html anchor, 3)url, url description, 4) urlEncoded... What am I missing here?
<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>Purchase Characterization</listName>
<updates><Batch OnError='Continue'>
<Method ID='1' Cmd='New'>
<Field Name='ContentType'>CharacterizeServers</Field>
<Field Name='parentRqID'>1234</Field>
<Field Name='Title'>XXXTitleXXXRequest ID:1234/Test - Do not process</Field>
<Field Name='RequestLink'>http://teams8xxxxRequest/DispForm.aspx?ID=1234</Field>
</Batch>
</updates>
</UpdateListItems>
</soap:Body>
</soap:Envelope>
Bill
Feb 19, 2013 at 3:12 PM
Edited Feb 19, 2013 at 3:12 PM
I think if you change this line:
<Field Name='RequestLink'>http://teams8xxxxRequest/DispForm.aspx?ID=1234</Field>
to something like this:
<Field Name='RequestLink'>http://teams8xxxxRequest/DispForm.aspx?ID=1234, Display Text</Field>
it'll work as expected.

Cheers,
Matthew
Feb 19, 2013 at 8:28 PM
Matthew,
Thanks for the suggestion. I tried this on a test list and was unsuccessful. Here is the POST:
<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>{34F5F005-0B18-4D48-BCE4-6293D5A523F6}</listName>
<updates>
    <Batch OnError="Continue">
    <Method ID="1" Cmd="New">
        <Field Name="Title">Test websvc add</Field>
        <Field Name="linky">http://www.google.com,Google</Field>
    </Method>
    </Batch>
</updates>
</UpdateListItems>
</soap:Body>
</soap:Envelope>
The response was
<UpdateListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
    <UpdateListItemsResult>
        <Results>
            <Result ID="1,New">
                <ErrorCode>0x80004005</ErrorCode>
                <ErrorText>Cannot complete this action. Please try again.</ErrorText>
             </Result>
        </Results>
    </UpdateListItemsResult>
</UpdateListItemsResponse>
Removing the ",Google" from the update request allows the function to complete successfully. However, it still displays as text, not a link.

Bill
Coordinator
Feb 19, 2013 at 8:39 PM
Bill:

I just ran this in the IE Developer Tools interactively on a generic Links list and it worked:
    $().SPServices({
        operation: "UpdateListItems",
        async: false,
        batchCmd: "New",
        listName: "Links",
        valuepairs: [["URL", "http://google.com, Google"]],
        completefunc: function(xData, Status) {
        }
    });
Maybe there's something we're not seeing because you haven't posted your code?

M.
Feb 19, 2013 at 8:53 PM
Marc, thanks for jumping in. Here is what I am using for a test case. I don't see anything different other than a space after the comma. After testing I found that the space is REQUIRED for this call to work correctly... Mystery solved.
        var values = [
            ["Title", "Test websvc add"],
            ["linky", "http://www.google.com,Google"]
        ];

        $().SPServices({
            operation: "UpdateListItems",
            async: false,
            batchCmd: "New",
            listName: "{34F5F005-0B18-4D48-BCE4-6293D5A523F6}",
            valuepairs: values,
            completefunc: newEntryCompletion
        });
Coordinator
Feb 19, 2013 at 9:16 PM
Yup, I just caused the same error you were getting by removing the space.

Sometimes it's the little things...

M.
Jun 19, 2013 at 12:46 PM
Thanks again Marc, Having a space proper in link & description part worked for me
Apr 23, 2014 at 7:52 PM
Hi RocklinBillbr,

I just came accross this library today and seems very promising.

I need an icon on the top ribbon bar that, when the user clicks on it, the current URL of the page is saved to a list of links (My Links list), and looks like you have done that already.

Can you please give me a quick step guide on how to implement that? The icon is on the master page. I am using SharePoint 2010.

Thanks,

Marco Garibay
Apr 23, 2014 at 8:27 PM

Marco,

It has been a couple of years since I was working with SharepointServices. I assume you are wanting to use client side tools to make this happen? If so you can research the sharepoint client-side object for both .net and javascript.

Bill

Apr 23, 2014 at 8:30 PM
RocklinBillbr wrote:
Marco, It has been a couple of years since I was working with SharepointServices. I assume you are wanting to use client side tools to make this happen? If so you can research the sharepoint client-side object for both .net and javascript. Bill
Hi,

Yes, thanks. So you don't recommend the SharePointServices library anymore?

Marco
Apr 24, 2014 at 1:28 PM

Marco,

I do highly recommend it. My job currently doesn’t involve SharePoint at all. In my previous position I wrote 50,000+ lines of javascript utilizing SPS to build a custom application that is still in use. In our company IT locks down most of the development features of SharePoint, so I utilized Marc’s library extensively. Using the library allowed me to make the SP forms very dynamic based on business rules.

Bill