4

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?

  • And if you disable the Publishing Feature? – Danny '365CSI' Engelman Jan 22 '16 at 16:13
  • Oh, I don't know. I can't really do that because many things depend on it being enabled. – bgmCoder Jan 22 '16 at 16:49
  • I have a vague suspicion the Announcements list is under SharePoints control; just like Links in Pages and the QuickLaunch are changed/managed by SP... but I do not know a solution for you – Danny '365CSI' Engelman Jan 22 '16 at 17:19
  • 3
    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. – Eric Alexander Jan 22 '16 at 21:08
  • 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 Jan 22 '16 at 21:13
3
+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

  • 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 Mar 3 '16 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 Mar 3 '16 at 15:22
  • 1
    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 Mar 3 '16 at 15:29
  • Glad that helped! – Paul Lucas Mar 3 '16 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 Sep 26 '16 at 22:05
0

SharePoint converts absolute URLs to relatives, and generally it's very useful feature. I'd try to shift the focus a bit here. What if it's the SPD activity causing that problem?

At https://spdactivities.codeplex.com/ there is this release announcement from Feb 21 2008:

Added 2 new activities. First one is the much awaited Copy List Item Extended Activity. The second is the Send Email Extended, which allows you to specify the sender. Also does not break links in body.

I'm not sure what exactly "break links" part means. Did Send Email in SPD 2007 break them, and this solution fixed it? Maybe that year 2008 fix breaks the links when executed in 2010? I'd like to check, but I don't have 2007/2010 farms anymore.

Just a hypothesis.


Maybe you can replace the activity with OOB one to test?

enter image description here

  • Sharepoint strips the domain. I know this from other posts and blog sites. Besides, if I create a link in an Announcements list that does NOT use any workflow at all, the domain is still stripped out. You can see it by opening the announcement in edit mode and going to check the link url - the url will be stripped. However, if you hover over the link, the browser will display the entire url - must be some javascript. – bgmCoder Mar 3 '16 at 14:49
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;
};
  • I added this function to the master page, but it doesn't seem to have any effect. – bgmCoder Mar 3 '16 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 Mar 3 '16 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. – Alexey Krasheninnikov Mar 4 '16 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 Mar 4 '16 at 14:49
  • 1
    Please take no offense, it was not intended. Just a cautionary note. – Alexey Krasheninnikov Mar 9 '16 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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