Inserting rich text content into comment in Flow Designer

perkinsarm
Mega Guru

I have an Update Incident Record step in a Flow which handles a special incident type. The step updates a number of fields including Additional Comments.

The customer would like for us to do two things:

  1. "@t mention" the caller in the comment.
  2. Insert some rich text to highlight changes that may need to be performed by the Assignment group.

I would think this might be possible by scripting the Additional comments field assignment but haven't been able to make it work.

  • Simply inserting @<First Name Last Name> doesn't result in an at mention.
  • Wrapping the desired rich text in [code]<p><html markup goes here></p>[/code] doesn't either.

If this is possible, what am I missing? 

Thanks

 

1 ACCEPTED SOLUTION

perkinsarm
Mega Guru

I was able to solve the @mention issue.

 

 

var addlComments = "@[" + fd_data.trigger.current.caller_id.sys_id + ":" + fd_data.trigger.current.caller_id.user_name + "]"

 

 

A hint to the solution was found here.

 

You need to use @[sys_id:user_name]

View solution in original post

3 REPLIES 3

Punit S
Giga Guru

To "@mention" the caller in the Additional Comments field, you can use the following format: "@<sys_user_name>".

For example, if you want to mention the caller with the user name "john.smith", you can add the following text to the Additional Comments field:

 

@John.smith

 

To insert rich text, you can use HTML tags within the Additional Comments field. For example, to highlight text in bold, you can use the following HTML:

 

<b>Highlighted Text</b>

 

You can also use other HTML tags for formatting, such as <i>  for italics and <u> for underlining.

Here's an example of how you can combine these two features in a script to update the Additional Comments field:

 

// Get the current incident record
var gr = new GlideRecord('incident');
gr.get(current.incident);

// Get the caller user record
var caller = new GlideRecord('sys_user');
caller.get(gr.caller_id);

// Update the Additional Comments field
gr.comments = "Attention @<" + caller.user_name + ">:\n";
gr.comments += "<p><b>Changes required:</b> Please review the updated details and take necessary action.</p>";

// Update the incident record
gr.update();

 

In this example, the script first gets the current incident record and the caller user record. It then constructs the text for the Additional Comments field, using the "@mention" syntax and HTML tags. Finally, it updates the incident record with the new comments.

 

Please mark my answer correct/helpful in case it adds value and moves you a step closer to your desired ServiceNow solution goal. 

Thanks,
Punit

 

@Punit S , I am finding that the suggestion partially works when implemented in an Update Record action in a flow.

var addlComments = "@<" + fd_data.trigger.current.caller_id.user_name + ">";
addlComments += ", your request is being processed."
return addlComments;

The result is that the literal  string with the < and > appears and ServiceNow does not recognize the entry as an @mention. Is there something wrong with my syntax or is this not possible within a flow?

 

I had to use the [code] tags technique that is documented in this article to insert the styled text.

var addlComments = "[code]@<" + fd_data.trigger.current.caller_id.user_name + ">"
addlComments += " , your request is being <b style=\"color:red\">processed</b>.[/code]"
return addlComments;

 

perkinsarm
Mega Guru

I was able to solve the @mention issue.

 

 

var addlComments = "@[" + fd_data.trigger.current.caller_id.sys_id + ":" + fd_data.trigger.current.caller_id.user_name + "]"

 

 

A hint to the solution was found here.

 

You need to use @[sys_id:user_name]