
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 05:44 PM
Ok, so I'm creating a flow action that gets the last comment - that part works fine, however it shows like this:
Ultimately I want to only use the text after the (Comments) part like:
This line removed:
The script I have currently is not showing anything after it tries to remove the text.
var str = inputs.full_comment;
str = str.substring(str.indexOf(")") + 1)
outputs.comment = str;
With my input being called "full_comment
My output being called "comment"
I can see in the results that it is getting the full comment, but then not showing any text as a output "comment"
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2024 04:40 PM
@Moedeb - Thanks.
Honestly, I think it's related to your first "look up record" step and how you're receiving the "Comments" as an input (which SN doesn't seem to be able to handle). Instead of receiving the comments as an input, try and receive the entire record, and then grab the comments journal entry in your script:
(function execute(inputs, outputs) {
var fullComment = inputs.approval_record.comments.getJournalEntry(1);
var trimmedComment = fullComment.substring(fullComment.indexOf(")") + 1);
outputs.comment = trimmedComment;
})(inputs, outputs);
Example:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2024 04:49 PM
@Nick Parsons you are completely correct - tried what you put and it 100% works exactly how I want it too!
Thank you a heap.
Also thank you to:
All of you trying to help is awesome and exactly what I love about the ServiceNow community
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2024 07:29 PM
Glad to help.
As per new community feature you can mark multiple responses as correct.
If my response helped please mark it correct as well 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
12-15-2024 04:50 PM
Also, a more robust solution would be to use the new line character as the marker for where the first line ends, not the ")" character which may potentially be included in the user's name, given you issues. So instead, I'd suggest:
(function execute(inputs, outputs) {
var fullComment = inputs.approval_record.comments.getJournalEntry(1);
var trimmedComment = fullComment.replace(/.*\n/, '');
outputs.comment = trimmedComment;
})(inputs, outputs);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 07:31 PM
Hello @Moedeb
Something like this...
Newcomments = inputs.full_comments.getJournalEntry(1).match(/\n.*/gm).join('').replace(/^\s*\n/gm
Please refer the below thread:
Please mark the answer as helpful and correct if helped.
Kind Regards,
Ravi Chandra

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 08:29 PM
It doesn't like that at all, for some reason thinks there should be another bracket at the end.