
- 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-12-2024 09:09 PM
Hi @Moedeb ,
you can adjust the action to take sysID as input you can also include one more choice input with choices as comment, work_notes and in custom script you can add this script.
this way you can reuse the action in flow to extract the last added comment this won't add the timestamp and user info. it just extracts the comment/worknote value
var cmGr = new GlideRecord("sys_journal_field");
cmGr.addEncodedQuery("name=sysapproval_approver^element=comments^element_id="+approvalRecodrdSysID/*replace with approval record sysid*/);
cmGr.orderByDesc('sys_created_on');
cmGr.setLimit(1);
cmGr.query();
if (cmGr.next()){
gs.info(cmGr.getValue('value'));
}
Please mark the answer as helpful and correct if helped.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 09:39 PM
Hi @Moedeb
You can try below approach and see if it works for you. Please note that this approach will only work if you want to skip the first line of the comment everytime.
// Gather the Full comment
var fullComment = inputs.full_comment;
//Declare a string variable to capture the final trimmed comment
var finalComment = '';
//Split the Full Comment on New Line
fullComment = fullComment.split('\n');
// Iterate through the comments, skip the first one and add it to your final comment variable
for(var i =1;i<fullComment.length;i++){
finalComment+= fullComment[i]+'\n';
}
// Set the Final Comment to your comment variable
outputs.comment = finalComment;
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 10:00 PM
@Amit Verma thank you, I believe I would always be happy to remove the first line, however for whatever reason this is also not working. Simply shows as blank
Not sure after all the help I've been given if there is something I've done incorrectly with the output value or in the way it is being used as an action?