We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

How to Add HTML Styled Comments Using Update Data Resource in UI Builder

SaiShivaniS
Tera Contributor

Hi everyone,

 

I'm working in ServiceNow UI Builder, and trying to update a record using the Update Data Resource triggered from a button's event handler. Specifically, I want to add a comment like this with HTML formatting:

html :<b style='color:red;'>Incident has been escalated</b>

Here's the script I'm using in the event handler:


/**
* @Param {params} params
* @Param {api} params.api
* @Param {any} params.event
*/
function evaluateEvent({
api,
event
}) {
if (event.payload.item.id === 'escalate') {
return {
table: api.context.props.table,
recordId: api.context.props.sysId,
templateFields: "comments=<b style='color:red;'>Incident has been escalated</b>"
};
}
}

But when the update happens, the comment is saved as plain text (i.e., the tags show up in the comment) instead of rendering as formatted HTML.

 

Is there a way to make the comment accept and render HTML formatting like bold/red text?

Any suggestions or best practices would be appreciated!

Thanks in advance!

 

#UI Builder 

 

2 REPLIES 2

Not applicable

@SaiShivaniS Try with [code] tag like below

 

[code]<b style='color:red;'>Incident has been escalated</b>[/code]

 

Hope this answers the query and if it does, please mark the answer as correct response.

SaiShivaniS
Tera Contributor

@Community Alums  I have added [code]<b style='color:red;'>Incident has been escalated</b>[/code] its not working if i remove  style='color:red; then text its added as bold, my requirement is to add additional comments in bold and red color text.