HTML field not rendering in portal widget

Steve McGrath
Tera Contributor

Hi,

We recently modified our Incident form description field to html. This is working well in the platform, however, our portal description now displays the html code when viewing the ticket form. The widget "ticket fields updated" only renders plain text. I'm not sure how to get the widget to display correctly. Any help or guidance is very much appreciated.

find_real_file.png

 

find_real_file.png

 

1 ACCEPTED SOLUTION

Oleg
Mega Sage

It's not enough to modify the Server Script by including the name of HTML field ("u_description_2" in your case) in the list of displayed fields:

var fields = $sp.getFields(gr, 'number,state,short_description,u_description_2,sys_created_on,watch_list');

You have to modify the Body HTML Template of the widget by including the line like the following

<sp-html-content ng-switch-when="html" model="::field.value" />

near the line number 23.

The corresponding fragment of HTML code will look:

<dd class= "col-md-6 col-sm-12 col-xs-6 break-word" 
	ng-repeat-end ng-switch="field.type" 
	ng-if="field.value && (field.type != 'decimal' || field.type == 'decimal' && field.value != 0)">
  <sp-html-content ng-switch-when="html" model="::field.value" />
  <div ng-switch-when="glide_date_time" title="{{field.display_value}}">
	<sn-time-ago timestamp="::field.value" />
  </div>
  <div ng-switch-default >{{field.display_value}}</div>
</dd>

View solution in original post

7 REPLIES 7

Oleg
Mega Sage

It's not enough to modify the Server Script by including the name of HTML field ("u_description_2" in your case) in the list of displayed fields:

var fields = $sp.getFields(gr, 'number,state,short_description,u_description_2,sys_created_on,watch_list');

You have to modify the Body HTML Template of the widget by including the line like the following

<sp-html-content ng-switch-when="html" model="::field.value" />

near the line number 23.

The corresponding fragment of HTML code will look:

<dd class= "col-md-6 col-sm-12 col-xs-6 break-word" 
	ng-repeat-end ng-switch="field.type" 
	ng-if="field.value && (field.type != 'decimal' || field.type == 'decimal' && field.value != 0)">
  <sp-html-content ng-switch-when="html" model="::field.value" />
  <div ng-switch-when="glide_date_time" title="{{field.display_value}}">
	<sn-time-ago timestamp="::field.value" />
  </div>
  <div ng-switch-default >{{field.display_value}}</div>
</dd>

Sri Bhavani
ServiceNow Employee
ServiceNow Employee

Hi @Oleg, thanks for this solution. But when I implemented that, I see code tags are also getting added before and after the actual content. That means, html is getting rendered but it is not rendering that code tags. Can you tell if there is any way to render that also? 

Steve McGrath
Tera Contributor

Oleg,

 

That worked! Thank you so much for the assistance! Much appreciated.

 

Steve