At the end of the previous post, we had this aha moment when we realized that rendering a field as rich text might not be that difficult, after all.
I’m back, after taking the time to set up a brand new demo to confirm our assumptions:
It works! As you guessed, just using a SharePoint Designer workflow to copy the content of the calculated column to a rich text field did the trick. For the record, here are the detailed steps:
- Create a list (I used the Tasks template here).
- Create a calculated column called cc, with the html formula. For the above demo I used calculated gradients (just did a copy/paste of the formula in the post).
- Create a column of type “Multiple lines of text” called HTMLcc, and specify that the type of text is “Enhanced rich text”.
- Create a one step workflow that copies the cc column to the HTMLcc column, every time an item is created or modified (screenshot below)
- We’re done!
The benefit of this approach is that we now have a clean field that renders our graphic – no ugly code around. I left the cc field visible for the purpose of the demo, but in production I would naturally make it a hidden field.
Although this looks great and easy, there are a couple gotchas to be aware of, if you decide to use this trick.
First, it is rather heavy: two fields and one workflow! And of course it won’t work for you if SharePoint Designer is not allowed in your environment (or you’ll need another way to copy cc to HTMLcc).
Second, it won’t help in views such as calendars, as these views don’t render rich text fields.
Third, as with any workflow action there’s a latency. The HTMLcc field will not refresh as quickly as other fields.
One last, important point: SharePoint is going to “sanitize” the html you copy to the HTMLcc field, and might decide to remove some of the content. This can actually be considered a good thing, as it addresses a security concern I reported in a previous post. On the other hand, it will block some script-based enhancements, like hover effects or countdowns.
Enjoy, and see you for next year’s trick: how to sort a list by month name. Happy Halloween!