When dealing with hyperlinks in SharePoint, users often point out the two following limitations:
– in a links list, there is no option to open a link in a new window.
– When using calculated columns to build URLs, the result is not displayed in a user-friendly way.
There are various methods to work around these limitations. Today I am going to show mine, which has the advantage of only using the SharePoint UI (no need for SharePoint Designer).
The issue
To understand the issue, let’s build a list of links pointing to the Microsoft SharePoint newsgroups:
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.sharepoint.design_and_customization
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.sharepoint.development_and_programming
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.sharepoint.general
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.sharepoint.setup_and_administration
First, we create a custom list (Site Settings > Create > Custom list), call it “Microsoft newsgroups”, and add these four items:
sharepoint.design_and_customization
sharepoint.development_and_programming
sharepoint.general
sharepoint.setup_and_administration
The second step is to create a calculated column to build the links to the newsgroups:
Name: “URL”
Type: Calculated column
Formula:
= CONCATENATE ("http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.", [Title])
Let’s take a look at the result:
As expected, we have been able to build our URL, and the browser has interpreted it as a hyperlink. But the display is not very user-friendly. We’d prefer to just see the titles, for example “sharepoint.general”.
Building an user-friendly list of links
To achieve this result, I am going to apply to the above list my method: using calculated columns to write HTML.
This is the HTML I need (Title displayed, and on click open URL):
<DIV><a href=”URL”>Title</a></DIV>
So in SharePoint I am going to change the [URL] formula to this:
=CONCATENATE("<DIV><a href='","http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.",Title,"'>",Title,"</a></DIV>")
Now, the final touch: add the script to convert the string to HTML (how?), and you should now see this:
What is still missing is the option to open the link in a new window. Here are the steps:
– create an additional column in your list:
Name: “Open in new window?”
Type: Yes/No (check box)
– change the formula in the URL to this:
=CONCATENATE("<DIV><a href='","http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.",Title,IF([Open in new window?]=TRUE,"' target='_blank' ","'"),">",Title,"</a></DIV>")
Here is the final formula in clear (but you should actually copy/paste the above one):
=CONCATENATE(“<DIV><a href='”,”http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.”,Title,IF([Open in new window?]=TRUE,”‘ target=’_blank’ “,”‘”),”>”,Title,”</a></DIV>”)
As usual, feedback is welcome!
Pingback: EndUserSharePoint.com: How to create links, labels and coloring in a SharePoint list : End User SharePoint
Does this work in WSS? I cannot copy your link as you indicate but I copied the text that is displayed. I get an error message, just wondering if it is ok with WSS?
Yes, this works in WSS.
Due to the page formatting, the end of the formulas is hidden. You should still be able to select the whole formula with a triple click.
If you use the formula in clear at the end of the post, type it yourself in the calculated field, do not copy/paste.
If you have any doubt, feel free to send me the formula you used(Christophe@PathToSharePoint.com) and I’ll double check it.
I am having the opposite issue. Our SP Site is opening a new window which doesn’t load as well as opening into outlook. I want the “open a new window” to not happen. I merely want it to open outlook. We are also having an issue with clicking on an internal pdf opening in a new window when I want it to stay local. How can I fix this and is it possible that it is at the server level?
Thanks
Jeremy, it’s hard to tell and will depend on the link. In some cases the behavior is driven by a script, this will be difficult to change (and specific to each case).
Christophe – When creating a link, I’d like to be able to use the [Name] column (file name), but [Name] is not an available column when creating the calculated string. Is there a way to access the [Name] column in the formula so that it won’t have to be hardcoded?
=CONCATENATE(“”,Name,””)
Sorry Mark, I am not aware of a way to use [Name] in calculated columns. Same issue for fields of type hyperlink, picture or lookup.
If you don’t want to take the SharePoint Designer path, a trick would be to include some JavaScript in the upload form, that would capture the name and copy it to another field. This is risky, as changes happening outside the upload form (for example in explorer view) wouldn’t be captured.
Hi, I had tried the method but couldn’t get it.
Actually I’m trying to navigate my task records when I’m in the view/edit screen. I created a Calculated field with formula, =”http://sharepoint.teleatlas.com/sites/apac/GDPtest/Lists/Tasks/DispForm.aspx?ID=”&(ID-1), and I just want to display it as “Previous Rec” instead of the whole hyperline.
Could I know how to do it?
Thanks
Interesting idea, but… unfortunately you cannot use the ID field in a formula. See a list of restrictions here:
https://pathtosharepoint.wordpress.com/2008/08/07/calculated-columns/
The formula would have been something like this:
=CONCATENATE(“[a href=’http://sharepoint.teleatlas.com/sites/apac/GDPtest/Lists/Tasks/DispForm.aspx?ID=”, ID-1, “‘ rel=”nofollow”]Previous record[/a]”)
(replace brackets with angle brackets)
Hello
Is it posible to remove the filtering row on top on the data rows? I’m using this trick to create a menu with links to other pages but I don’t like showing the name of the field as a filtering row. I don’t want people filtering the view.
I’m using WSS 3.0.
Best Regards
Antonio, why wouldn’t you let people filter the view if it helps them?
I don’t see an easy way without SharePoint Designer.
As you are looking for a menu, have you tried this alternate option:
https://pathtosharepoint.wordpress.com/2008/08/20/a-simple-drop-down-menu/
Christophe, first of all thank you for your support.
I’m using one links list for the whole site. The site has a lot of differente pages (it’s an Intranet) and each page has a link web part. In order to avoid a lot of links lists, I’ve just created one with some fields that work as filters. So when anyone creates a new page and needs a links list, the common links list is used and the user creates a new view for than page.
In that case, the user shoudn’t be filtering, as what he’s seeing is the linsk for the specific page.
Is it posible with Designer? Although I don’t have the tool I could ask some guys from other department to see if they can made the changes.
Best regards
SPD will remove whatever you want in a snap. Problems usually start when you realize you have removed too much… If you are not familiar with SPD, ask for advice first. On this blog you can start with my article on the Data View Web Part:
https://pathtosharepoint.wordpress.com/2008/08/24/your-first-data-view-web-part/
Next month I’ll publish more articles on menus, hope you’ll find something to your taste.
Thank you, Christophe, I will give it a try.
Christophe, this does not seem to be working for me. I entered the following to test if it would work:
=CONCATENATE(“TEST“)
But all got was the following line in the Column.
TEST
I should expect only the word “TEST” in the column, correct? And if I press it, then it should should direct me to the url. Not working as expected though. Any help would be appreciated.
Steve, there’s a troubleshooting section here:
https://pathtosharepoint.wordpress.com/2008/11/01/troubleshooting-your-html-calculated-column/
If it still doesn’t work, send me your formula by e-mail.
So here is a question. When I set up new sites, on the home page I had a links list setup so users can add their own links and it would only display thier links, like a My Links view. When you add this link to the web zone it removes the column headers and creates a bulleted type list of the links. I created this custom list added it and it works perfectly, but I can not remove the column header, and I am not sure How I can make the view display as a bulleted list. Can this only be done with a links list?
Larry, I also tried a “My Links” view in a department, but it never worked. People sticked to their browser bookmarks.
Are you saying that you used the method described in this post? In this case, you should be able to get the bullets by adding a “li” tag in the formula.
I often see questions about modifying the look of Web Parts (title background, remove buttons, hide column header), and I’ll publish a script for this. I have no magic trick, just regular CSS.
What I usually do in such cases is create the view from scratch. For a list of links, I would for example:
1/ grab the list content using the URL protocol:
https://pathtosharepoint.wordpress.com/2008/09/24/using-the-rpc-method-via-the-url-protocol/
2/ use Javascript to make it a drop-down menu, like here:
https://pathtosharepoint.wordpress.com/2008/08/20/a-simple-drop-down-menu/
Duh, I should have thought about the li tags. That is simple enough. Ireading the rest of your solution I guess I was making it harder that I should. Sorry now I will shut up. Thanks again. If you are in the states, have a great holiday!
Hi…
I want that my hyperlink should ALWAYS open in a new window. Also tell me if there is any way to HIDE a column… 🙂
Plz let me know about this asap…
Nice one but your article on this isn’t clear enough.
You stated:
First, we create a custom list (Site Settings > Create > Custom list), call it “Microsoft newsgroups”, and add these four items:
sharepoint.design_and_customization
sharepoint.development_and_programming
sharepoint.general
sharepoint.setup_and_administration
What type of colmn fields did you create e.g single line of text,hyperlink etc….
I have created a calculated column and i have pasted this sample link
=CONCATENATE(“Previous record“)
But if i do:
=”http://wknt250:8182/sites/TeamSite1.aspx?k=”&Title
I can get a link but i want a link like the one you created
Thanks
Do i need any javascript for this to work?
Hi Christophe,
I followed exact your steps
1.
2.
Formula:
= CONCATENATE (“http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.”, [Title])
And I got this error message:
“The formula contains syntax error or is not supported”
Did I miss something?
It’s due to the beginning blank space after the = sign
i.e = CONCENATE … should be =CONCENATE
Chelsea, I think the issue is with quotes formatting. I have corrected the post, note the subtle difference with what you pasted in your comment.
How are you disabling output escaping? I actually see the code with the div tags etc.
NM, found your link. Thanks
Hi,
Nice article ,if my list contains n number views,each views, i have to insert CEWP(java script code).is there any solution for this?
sanjaya: the solution is to insert the script before creating the views. Once you have included a CEWP with the script in the main view, every new view you create based on the initial one will have the script included.
Btw to facilitate later updates it is recommended to store the script in a document library and link to it from the CEWP.
Hi,
We are having DailyTracker custom list to track daily project activities.In this list we have one column Department ( Type – dropdownlist ). Is it possible to open values appearing in Department dropdownlist as Lookup window similar to Person or Group window with option for user to select.
I am new to SPS 2007. Please help me out.
Chris,
How would you do the opposite, i.e. extract the text value of a Sharepoint hyperlink?
Greg
Greg: I guess one solution would be to use a workflow to copy the hyperlink to a text column (but I haven’t tried).
Another approach would be to use a script that will run on the page to identify the html hyperlink and extract the link URL. I did something similar once to extract the item id from the title column.
Christophe – looks like this thread has been going for a bit –
Glad I found it 🙂
I’m trying to simply copy the 1st part of the concat script and getting an error thrown back at me:
My Formula:
= CONCATENATE (“http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.”, [Title])
Error:
The formula contains a syntax error or is not supported.
Using:
WSS 3.0
Any ideas?
Make sure you use normal quotes (not formatted quotes from Word for example). Other than that, I see no reason why it wouldn’t work.
Good day Chris, first of all this is a very useful article.
Here’s the scenario. I am building a pretty much like a records management system. For example I have created two lists, first is the List of Records, and the second one is the Request Form for the user to request any records.
In the List of Records, I have created a calculated column named “Request this”. My suggestion is when user click the “Request this” link it will link to the (2nd list)Request Form’s New Item. Then user can fill in the details and then submit the form.
Could u please help me in this area?
Much Regards,
Fayadh
Well, simply apply this post to your specific case, it is exactly the same scenario.
Thank you very much for the quick reply.
I have already solved the problem. Apparently, i use ‘&’ instead of ‘,’ for the CONCATENATE parameters and it works.
Thanks for the tips Chris. I have followed u on twitter.
Have a nice day! 😀
Christophe,
Strange, but I was able to reference the ID in my calculated column that creates a URL string. My URL link needed to include a unique page to which the user should return based on Region. It works nicely, but now I want to wrap it in a hyperlink. I’ve been trying to follow instructions but get the “error in formula” message.
Here is my URL output
https://mycompany.com/Lists/Directory%20List%20%20Operations/DispFormGSO.aspx?List=e67ab1c7%2D8f74%2D4959%2Da0ef%2D7bea2e4e638a&ID=202&Source=https://gain.paegroup.com/Lists/Directory%20List%20%20Operations/KeyOA05.aspx
and here is my formula…
=CONCATENATE(“https://mycompany.com/Lists/Directory%20List%20%20Operations/DispFormGSO.aspx?List=e67ab1c7%2D8f74%2D4959%2Da0ef%2D7bea2e4e638a&ID=”,ID,”&Source=https://gain.paegroup.com/Lists/Directory%20List%20%20Operations/”,[Calc aspx page])
I’ll continue banging at it. Is it required that I have a “Open in New Window” column?
SharePoint won’t give you an error message, but still ID is not in the list of allowed fields in formulas.
If you don’t need the “open in new window” part, just remove the IF from the formula.
Christophe,
I appreciate the feedback. Got it to work. I broke out the calculated column into two calculated columns. However, I may have to try another approach using workflow and a hyper link field. Here is why…
The list in which I am trying to display the link is in datasheet view. When in DS view, the code is displayed. Is there a workaround for this other than the workflow option that I found here? (link and steps below)
Again, a BIG thanks.
===============================================
http://social.msdn.microsoft.com/Forums/en-US/sharepointcustomization/thread/65d37c53-116a-4405-aa7a-1aeff26ad3ff/
= = = = = = = = = = = = = = = = = = = = = =
What I normally do:
Create an optional hyperlink column in the list
Create a worklflow with SharePoint designer that starts on Item Created and with no conditions
In the workflow, create an “Store dynamic string” action and store into a new variable.
The dynamic string can then consist of your URL with lookups for any parameters you need. (Example: “http://www.google.com?q=[%YourItem:YourField%], Look up in google”. The comma and subsequent text makes sure it fits nicely with the Hyperlink data structure, where the latter part of the string becomes the displayed text for the link
Then add another action “Set field to value”, where you select the field from step 1 and for the value, the variable created in step 4.
Job done.
Proposed As Answer byKale Davis Wednesday, October 14, 2009 12:39 PM
To use a regular link list how can we set this computing field please kindly advice. I am unable to get it working
You are my life saver! 🙂
Question, my [title] column contains spaces which seems to cut off the URL when the first space is reached. Is there any way to account for spaces?
Great article btw.
Hi Cristophe,
I followed your instructions but I can still see the tags and the clickable part it the one with the url. Here’s my syntax:
=CONCATENATE(““,idnumber,”“)
Kindly correct.
Thanks.
JC, I’d recommend that you follow the links in the post, and read the troubleshooting page.
Hello Christophe,
These instructions are exactly what I’m looking for and I’ve got it *mostly* working. The URL is formatted exactly like I want and have verified it will work. The only part not working is the script to transform it from text to html. I copied your script found in the link (https://blog.pathtosharepoint.com/2008/09/01/using-calculated-columns-to-write-html/), placed it in a text file and linked to it using the CEWP. Were there any changes you made to the script to get it to work on links instead of text formatting? Does the CEWP need to be last on the page or can it be first?
Thanks for your help.
The CEWP needs to be placed below the text you want to modify. As for the script, the latest version is 2.1.1 .
Thanks, Christophe. That worked!
hello ,
Thanks for such article. i somehow cannot hide the long url that is diplayed in the calculated column. i have used custom new form for that particular list, and jqueries to create cascade dropdown.
do u think that the already existing jquery is preventing this from working? i have even added a webpart (courtesy you), TextToHtml. even it has not helped.
Well, it should work if you followed the instructions in this post and included the TextToHTML.
Test the customizations one at a time to try and isolate the issue. Sometimes the order may be important, I’d suggest for example to have TextToHTML before jQuery.
Yes. Thanks a lot Christophe. The order was the problem. Never thought it would matter.
Hi Christophe,
Thanks for all your hard work. I love your solutions.
I have an extra field to add to my Concatenation and I had it worked out fine.
But when i go to try and enable the “Open link in new window” technique i just can’t get Sharepoint to accept my formula in URL column.
I’ve included the working sample below and if you’re not too busy i would really appreciate the help to get the Pop-Up window working.
=CONCATENATE(““,Status,”“)
Thanks very much
James
=CONCATENATE(““,Status,”“)
Thank you for all the suggestions on this page. My problem is somewhat different. I would like to use your suggestion of “open in a new window” but change it to “open on side frame”. How do I get a list in one zone to open one of my calendar vies on a different zone on the same page.
Thanks!
KTT
While this can be done, I would not recommend to use my technique for this. You are mixing an item property with a page layout, and this is not consistent. Instead, I’d recommend to add a script to the page that will cnnect your hyprlinks to the frame.
Thank you Christophe. Just a follow up question. Do you have an example I can show my boss?? Thanks!
Sorry, I don’t. This is not specific to SharePoint, so you should be able to find examples on JavaScript sites.
Christophe, the [Title] column I am referencing has multiple words, and the subsequent URL refrenecing the [Title] breaking. ie.:
http://www.mysharepointsite.com/pages/my page.aspx (the URL is only linking to “http://www.mysharepointsite.com/pages/my”
Is there a work around, or is there just a common practice of not referencing columns with multiple text in it?
In URLs, some characters need to be escaped. For example, you need to replace spaces with their encoded value:%20. In your example:
http://www.mysharepointsite.com/pages/my%20page.aspx
Thank you, that worked a treat 🙂
Thanks, most of it worked except for the last added column (Yes/No) which won’t show any checkboxes.???
I tried your method, but field still dont looks like hyperlink, its just a simple text
Doesn’t work.
Don’t copy and paste – the quote characters get pasted wrongly, e.g. ” vs. “ etc.
Even when I get the quotes working, the string still appears literally with the “…“.
So it’s not working.
* That should be with DIV / A characters.
Did you include the script below the list? Also, this post is quite old, check out more recent posts for updates.
You might also find this troubleshooting section useful:
https://blog.pathtosharepoint.com/2008/11/01/troubleshooting-your-html-calculated-column/
Great post! I have everything working except the CEWP for html conversion. I can get it working on any web pages that I create, but does this mean that I will never be able to convert to html when I’m viewing the list on the list page instead of another web page. If so, where do I put the CEWP. Thanks!
Nevermind, figured it out. My owner rights were not set correctly. Thanks anyways!
After going over a few of the articles on your web page, I truly like your way of blogging.
I book-marked it to my bookmark webpage list and will be checking back soon.
Take a look at my web site as well and let me know how you feel.
Hi Christophe:
I am struggling with my formula.
My list has these fields from which I need to create hyperlinks:
[URL]
[Title]
[Open in new window?]
I seem to be missing something in my formula. Would you see if you can spot my error?
=CONCATENATE("<DIV><a href=’",[URL],[Title],IF([Open in new window?]=TRUE,"’ target=’_blank’ ","’"),">",[Title],"</a></DIV>")
Thanks-
Charlie Epes
Sorry Charlie, I don’t understand the formula (but I would agree that it doesn’t look right). What is the expected result?
This technique was working flawlessly in our SP2007 environment, however since the upgrade to SP2010 the calculated field is once again showing as raw data (<a href…
Is there something in the java script that needs to change to make this work in SP2010?
Depending on your view options, the old code might not work in SP 2010. I’d recommend that you take a look at the posts published in 2010, where I shared some workarounds for SP 2010.
Pingback: SharePoint Calculated URL Column. | Tjen Sharepoint Blog
There are many possible solutions to make SharePoint Links to open in new window. Simple and easiest solution is: Create a Site column of “”Hyperlink with formatting and constraints for publishing” type and add it in your list, which enables you to specify “Open in New Window” Option!
Find the all possible solutions, including JavaScript, JQuery to SharePoint Link list – Open in a New Window at: http://www.sharepointdiary.com/2011/02/sharepoint-link-list-open-in-new-window_21.html#ixzz2aWqzWgLE
Thanks for sharing the link. Funnily the article you are mentioning misses the solution presented in this post 🙂
The “Hyperlink with formatting and constraints for publishing” is definitely an interesting choice, unfortunately it is not always available.
Hi Christophe! I’d like to create a calculated URL – but based on an existing column which is a hyperlink. (cannot refer to column of type hyperlink when building formula for calculated column) – probably some workflow thing required, huh?
Because of the limitations with hyperlink columns, I usually prefer to store links in a simple text field.You are right, you could use a workflow to copy the link to a text field, but it’s a heavy workaround.
Cristophe
I have been playing with this on a SharePoint 365 site. The original calculated column technique generates the HTML fragment as described, but displays the raw HTML instead of a clickable link. However, if I change the formula data type to “Number (1, 1.0, 100)”, instead of “Single line of text”, the link works. Just one gotcha though, the column is right-aligned.
I got the idea to try a Number column from:
http://sharepointwijzer.nl/sharepoint-blog/tech/icc-html-calculated-column-sharepoint-view/
Right, this number trick is also mentioned in the comments on this blog. I am not advertising it though, as it’s obviously a bug and I would expect Microsoft to fix this behavior in the future.
The approach I recommend in SP 2013 / Office 365 is to rely on Client Side Rendering. I posted an article with sample code a couple months ago.
Hi, it works perfectly!
I juste have an issue with the “Open in new window” part. The formula is correct, it’s rendered as a link in the list, but it doesn’t open it in a new window, even with the yes/no column, the IF and [open in new tab?]=TRUE..
Can you help me? Here is my formula :
=CONCATENATE(““,[myColumnToConcatenate],”“)
I use MOSS (SharePoint 2007), and I do have followed all the steps.
I’m familiar with this stuff since I used yours “How to” for the Color Parts too 🙂
PS: The formula is invalid if I remove the [myColumnToConcatenate]’s brackets.
I know there is something, but i don’t see it, maybe an “other eye” will help me.
Hi Christophe,
I have the following fields in a custom list:
“Title” – Single Line of Text, Required, Non-unique values, 255 chars, Default text (not used)
“SC_URL” (Site Collection URL) – Single Line of Text, Required, Non-unique values, 255 chars. Contains the FQDN of the Site Collection
“Site Settings” – Calculated column, data returned is Number.
Formula for “Site Settings” is:
=CONCATENATE(“<a href='[SC_URL]”,”/_layouts/settings.aspx”,”‘ rel=”nofollow”>”,”Site Settings”,”</a>”)
– Sample value in “SC_URL” is http://webapplication1.company.com/sites/sitecollection
– The list I’m using this in is in a different web application (http://webapplication3.company.com) than the sample value (http://webapplication1.company.com)
– The anticipated result is http://webapplication1.company.com/sites/sitecollection/_layouts/settings.aspx
– The resulting URL is http://webapplication3.company.com/sites/sitecollection/int/SPC/Lists/SCM/%5BSC_URL%5D/_layouts/settings.aspx
Any idea why this column is picking up my current webapp/managedpath/sitecollection/site/lists/listname instead of the URL in the Sample Value?
Thanks in advance for your help, all your solutions have been a great value to my development activities!
Best Regards,
Chris
Chris, [SC_URL] is a column name and should not be inside the quotes.
Is it possible to use a column for the beginning of the URL, or does that need to be a static in the formula?
both column and static text are fine, what really matters is the output of the calculation.