This project has moved and is read-only. For the latest updates, please go here.

Creating a link in the body of a discussion thread

Sep 16, 2014 at 5:40 PM
I'm using SPServices to create a new thread in a discussion list:
      operation: "UpdateListItems",
      async: false,
      batchCmd: "New",
      listName: "Document Reviews",
      valuepairs: [["ContentType", "Discussion"],
                        ["Title", newDiscussionTitle],
                        ["Body", "Post comments as replies to this thread after reviewing document. " + newDocURL],
                        ["BaseName", baseName]],
      completefunc: function(xData, Status) {
            xData_save = xData;
            Status_save = Status;
Creating the new list entry itself is working fine, but what I'd like is the text in the variable newDocURL to be an active relative URL link in the body of the discussion list entry; right now, it's being treated as just text.

When creating a new discussion thread manually, I do see that creating a link is a specific action in the editor (using a specific link dialog form), so I'm guessing that the link (the text and the URL itself) is treated as a special object of sorts in SharePoint. Is there anyway to replicate that with SPServices? Thanks in advance!
Sep 18, 2014 at 8:25 PM
You may be able to send the URL as encoded HTML. There is a function to do that for you....


For instance, if newDocURL is...
<a href="">Google>

then the STSHtmlEncode() function will send it as...
<a href="">Google</a>

I'm not sure if that's the sure fix but I've had to use it when sending HTML tags to SharePoint lists in the past.

Sep 18, 2014 at 10:10 PM
Edited Sep 18, 2014 at 10:17 PM
Actually, I was going to post that I figured out at least one way for it to work and then I saw your reply.

I first tried to put the anchor tag around the URL:

["Body", "Post comments as replies to this thread after reviewing document. <a href=\"" + newDocURL + "\">Link</a>"],

But it appeared the web service is spotting it and stripping from what gets saved (presumably as a security measure). But as one last try, I swapped the less than and greater than signs for the HTML equivalents (which may be what you posted but this site has converted them to < and >). And this appeared to work.
Sep 19, 2014 at 12:35 PM
You are correct....This site decoded my encoded URL. The STSHtmlEncode() function will make sure everything in the parentheses gets encoded properly for transit to the server. It's handy for sending data to any list where your updates may include reserved characters.