Sharepoint 2013 calculated field as hyperlink renders as text

不羁的心 提交于 2019-12-11 01:22:55

问题


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.

  1. Create a js file with code - in my case I create a hyperlink which posts to another list with values from current item.

  2. Copy link location of js file.

  3. Reference js file on web part on view, under section Miscellaneous.

  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!