- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 04:42 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 05:32 AM
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
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 05:03 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 05:20 AM
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/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2025 05:32 AM
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
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2025 07:32 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader