Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

NeerajS57169215
Tera Contributor

@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

@NeerajS57169215  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.