POSTS
How to fix Service Portal Widget rendering HTML as plain text ServiceNow
How to fix Service Portal Widget rendering HTML as plain text ServiceNow
I ran into an interesting issue while working with Service Portal in ServiceNow.
I cloned a widget that had details of Task on a table, this table was project. But this would apply to other tables as well.
I wanted to show the Description field in the widget. I did the usually declare the variable in the server script in the body html with brackets and added .getValue(). Example below. Which worked.
Code: {{data.description.display_value}}
The problem with this was that the description filed on the form was HTML type and not a string.
So it would render with HTML code showing up as plain text. Like this
test description
Which as you can see is not rendering the HTML but just outputting it as plain text.
The way around this is to use the ngBindHTML directive in Angular. The code would look something like this.
Code: ng-bind-html=“data.description.display_value”
Pretty simple just add in to the code ng-bind-html and set equal to the variable found in your servicer script and remove the brackets and place in quotes.
More information can be found on ng-bind-html directive in the following link below. A side note be careful when looking at the angular documentation ServiceNow is using an old version so make sure you are looking at the right one.
https://docs.angularjs.org/api/ng/directive/ngBindHtml
Special thanks to community article I found answering this question.