2

I'm trying to generate a hyperlink to an item page using a calculated column. I'm 99% of the way there, but I run into issues when the title has spaces.

My calculated column has the following formula:

=CONCATENATE(
  "<a href=https://oursite.sharepoint.com/sites/sitename/SitePages/Content%20Type.aspx?ContentType="
  ,[Title]
  ,">"
  ,Title
  ,"</a>"
)

The problem is in the first reference of Title. With our without brackets, if the title has a space, the title stops after the first word and fails to point to the correct page.

e.g.

Title = First Item Calculated Column Result = https://oursite.sharepoint.com/sites/sitename/SitePages/Content%20Type.aspx?ContentType=First Desired Result = https://oursite.sharepoint.com/sites/sitename/SitePages/Content%20Type.aspx?ContentType=First%20Item

Is there any way I can do this via calculated column?

3

I believe if you put the href in single quotes, anything displaying it will auto change the space to the correct %20. Just before the https, and just before the > at the end of the href.

=CONCATENATE(
  "<a href='https://oursite.sharepoint.com/sites/sitename/SitePages/Content%20Type.aspx?ContentType="
  ,[Title]
  ,"'>"
  ,Title
  ,"</a>")
  • Simple solution and worked beautifully. Thank you! – Andy Levesque Feb 28 '17 at 14:22
1

Your issue is that the Browser adds " quotes around the HREF tag
it adds a closing quote at the first space it finds in the string

You can enter those quotes yourself with escape notation;
two quotes: "" will output one quote " in the string

String concatenation can also be done with &

So your Formula becomes:

="<a href=""https://oursite.sharepoint.com/sites/sitename/SitePages/Content%20Type.aspx?ContentType="
  &Title
  &""">"
  &Title
  &"</a>"

The single quote mentioned in the other answer also works,
because the Browser will replace it with a double-quote.

Using the escape "" notation allows the single quote ' to be used for quoting URL string parameters
(like ContentType='string' if required) or in JavaScript code additions

So you can do: http://www.viewmaster365.com/#/How
Be sure to read the Pros & Cons of using HTML/JavaScript in Calculated Columns

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.