问题
I have a column in Sharepoint 2013 and set the type to 'Calculated'. I have set the data return type to integer (pic attached) so that the field is hyperlink.
All worked fine for over a year in all environments (dev and production) and browsers (chrome, firefox, IE) until recently when users reportted the hyperlink was not clickable anymore and displayed as text (pic attached). Inspecting the element, reveals the value of is treated as text.
I have spent some time simplifying the formula, removing fields and having a simple element to navigate to google, but have not found a solution. I suspect there may been a Sharepoint update which handles the formula differently creating text inside the element surrounding it with double quotes.
回答1:
After research I have found the cause and the solution to my problem.
Cause
SharePoint update removed the ability of calculated fields to be set us markups and is explained in Handling HTML markup in SharePoint calculated fields.
Solution
I have found a solution with JSLink. After opening link above, there are some examples using JSLink. With a bit of play-around, I managed to achieve having the calculated field as a hyperlink. The steps are simple.
Create a js file with code - in my case I create a hyperlink which posts to another list with values from current item.
Copy link location of js file.
Reference js file on web part on view, under section Miscellaneous.
Voila!
Note: in the script, the field name must be the internal field name, that slowed me down quite a bit. to get the internal field name, open list settings, hover over desired field and on the bottom left of your browser you get the internal field name (Field=Internal field name here).
JSExample can be found here.
Another helpful read here.
回答2:
As mentioned as a follow-up by the original poster, as of June 2017, you can't do this anymore.
For SharePoint Online, the alternatives are to embed some JavaScript on the page or to use the new SharePoint PnP Fx Extensions. If you have your own SharePoint Server, you can use the API [i.e. through PowerShell] to modify the Web object's CustomMarkupInCalculatedFieldDisabled property.
I needed a little bit more robust solution, so I created a SharePoint Extension to do this. You can view it from GitHub. The instructions should be able to get you up and running in a couple minutes. I find it much easier to manage than the JavaScript alternative.
来源:https://stackoverflow.com/questions/44801590/sharepoint-2013-calculated-field-as-hyperlink-renders-as-text