How to Remove time stamp and user info from additional comments in Flow Designer

wefw
Tera Contributor

Hi,
In flow designer we are using Send Email action. in body we need to attach Additional Comments from RITM/SCTask. so I am using Data Pill Picker and selecting Additional Comments from RITM but i am also getting time stamp and username in body.
How to remove these details?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@wefw 

that's expected outcome.

you can use a flow variable and get the latest comments and then set the value using Set Flow Variables and use this script

Then use this flow variable in your "Send Email" action

var latestComments = fd_data.trigger.current.comments.getJournalEntry(1).match(/\n.+/gm).join("\n");
latestComments = latestComments.replace('\n','');
return latestComments;

Something like this

latest comments in send email flow.gif

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Community Alums
Not applicable

Hi @ Use a Script Step to Extract Only the Latest Comment

(function execute(inputs, outputs) {
  var journal = new GlideRecord('sys_journal_field');
  journal.addQuery('element_id', inputs.taskSysId); // pass RITM/SCTask sys_id as input
  journal.addQuery('element', 'comments'); // for Additional Comments
  journal.orderByDesc('sys_created_on');
  journal.setLimit(1);
  journal.query();
  if (journal.next()) {
    outputs.latestComment = journal.value.toString();
  } else {
    outputs.latestComment = '';
  }
})(inputs, outputs);

Udayrathore049
Tera Contributor

Hi
To resolve this, you can use a simple script to clean up the comment content before including it in the email body. 

Script to Remove Timestamp and Username
In your Flow Designer, when setting up the "Send Email" action, you can use a script to clean the "Additional Comments" field. This script will remove the unwanted timestamp and username, leaving only the actual comment content:
var comments = current.comments; // Retrieve the Additional Comments field
var cleanedComments = comments.replace(/^\[.*\] /, ''); // Remove the timestamp and username
return cleanedComments;
The regular expression ^\[.*\] matches the timestamp and username pattern typically included at the beginning of the comment.

This script strips out those details, so only the comment text remains.

Use the Cleaned Comment in the Email Body
Once the script is implemented, use the cleanedComments variable in the "Send Email" action to populate the body of the email.

If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Uday Rathore
ServiceNow Developer
LinkedIn: https://www.linkedin.com/in/uday-rathore049/

Ankur Bawiskar
Tera Patron
Tera Patron

@wefw 

that's expected outcome.

you can use a flow variable and get the latest comments and then set the value using Set Flow Variables and use this script

Then use this flow variable in your "Send Email" action

var latestComments = fd_data.trigger.current.comments.getJournalEntry(1).match(/\n.+/gm).join("\n");
latestComments = latestComments.replace('\n','');
return latestComments;

Something like this

latest comments in send email flow.gif

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@wefw 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader