5

This is a weird one.

So I post an announcement in an announcements list. In the message body I create a link that points to a document library and am sure to include the domain name in the link.

There is a workflow attached to the list that will send the message as an email. But when it is sent out via email, the domain name is stripped from the link url and so it becomes a broken link!

I went into the message of the announcement afterwards and went to edit the link and, lo and behold! There was no domain name in the url! Even though I did use one originally.

I tried the same thing in an Announcement list without any workflow attached and found the same issue.

Anyone have a clue why this is happening? Is there a way to prevent this from happening? Maybe a setting somewhere?

Does anyone have a solution for this behaviour?

8
  • And if you disable the Publishing Feature? Commented Jan 22, 2016 at 16:13
  • Oh, I don't know. I can't really do that because many things depend on it being enabled.
    – bgmCoder
    Commented Jan 22, 2016 at 16:49
  • 4
    SP does this a lot, strip out absolute URLs and makes them relative. I'd say to not insert a hyperlink and just try typing the url normally. Outlook is typically smart enough to turn it into a clickable hyperlink then. Commented Jan 22, 2016 at 21:08
  • 1
    Yeah, but sharepoin urls are really ugly - especially if it leads to a list item or a library item. But at least, you are right, it is a workaround.
    – bgmCoder
    Commented Jan 22, 2016 at 21:13
  • 1
    Also, if you type out the url, it doesn't get hyperlinked in the actual announcement on the portal.
    – bgmCoder
    Commented Mar 3, 2016 at 1:48

2 Answers 2

4
+50

Here's an example of using a 2013 workflow step to read the Announcment body into a variable called Body, use a "Replace Substring In String" action to replace the text 'href="/' with 'href="http://urltosp/' and then output the updated text to the variable.

You can then send the variable contents in your email.

enter image description here

5
  • Everything is 2010 (I tagged my question that way, actually) - but this is not a bad idea. Maybe I can add something like this to my workflow that sends the email.
    – bgmCoder
    Commented Mar 3, 2016 at 14:33
  • This actually works! I can't believe it! And for the record, any richtext formatting IS retained after the replacement. This is the solution. I'll give you the reward, but I have to wait for 10 hours, says the site.
    – bgmCoder
    Commented Mar 3, 2016 at 15:22
  • 2
    This has the advantage that the relative links are preserved in the actual announcement item, whilst the absolute url is inserted into the email message.
    – bgmCoder
    Commented Mar 3, 2016 at 15:29
  • Glad that helped!
    – Paul Lucas
    Commented Mar 3, 2016 at 20:37
  • PLEASE also note that if you are using single quotes in your href attribute (as Javascript allows you) Sharepoint converts it to double quotes. So do it exactly like @PaulLucas has laid out regardless of if you thought you used single quotes....... Sharepoint... The only development tool I've ever used where the developers are okay with the development tool changing their code :P
    – Riggy
    Commented Sep 26, 2016 at 22:05
0

This behavior seems to be by design, it's supposed to work with alternate access mappings, but emails are clearly not considered. There's a function in SharePoint Rich Text Editor JavaScript that strips the domain, so if you switch to plain text, your HTML source will not be modified.

See this Q&A as well Absolute URLs converted to Relative URLs when saving item

Below is an excerpt from the out-of-the-box SharePoint javascript, for illustration purpose only. Not to be used as a solution.

RTE.RteUtility.$EI = function (a) {
    ULSNVe:
    ;
    var b = new RegExp("[^:]*://" + window.location.hostname + "(:|/)", "i"), c     = new RegExp("[^:]*://", "i");
    return a.search(c) === -1 || a.search(b) !== -1;
};

RTE.RteUtility.$4O = function (e) {
ULSNVe:
    ;
    var a = e, d = window.location.protocol, b = d + "//" +
        window.location.hostname, c = window.location.port;
    if (c === "")
        if (d === "https:")
            c = 443;
        else
            c = 80;
    if (c === 80 && d === "http:" || c === 443 && d === "https:")
        if (a === b)
            return "/";
        else if (!a.indexOf(b + "/"))
            return a.replace(b + "/", "/");
    b += ":" + c;
    if (a === b)
        return "/";
    else if (!a.indexOf(b + "/"))
        return a.replace(b + "/", "/");
    return a;
};
8
  • I added this function to the master page, but it doesn't seem to have any effect.
    – bgmCoder
    Commented Mar 3, 2016 at 1:34
  • In my case this is happening in an announcements list which gets sent to an email distribution list via workflow. I can't change it to plaintext - it has to be richtext.
    – bgmCoder
    Commented Mar 3, 2016 at 1:41
  • You shouldn't have added this function - it's already there out of the box. I added the code to illustrate what exactly it replaces in the HTML. You could override it, however, as needed. Commented Mar 4, 2016 at 5:56
  • Sorry, I couldn't tell that you weren't suggesting for me to add it... It didn't seem to do anything so I removed it. So, this isn't really a solution, just useful information.
    – bgmCoder
    Commented Mar 4, 2016 at 14:49
  • 1
    Please take no offense, it was not intended. Just a cautionary note. Commented Mar 9, 2016 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.