Help with flow action getting comment and removing some default text

Moedeb
Tera Guru

Ok, so I'm creating a flow action that gets the last comment - that part works fine, however it shows like this:

Moedeb_0-1734053940068.png

Ultimately I want to only use the text after the (Comments) part like:

Moedeb_1-1734054000896.png

This line removed:

Moedeb_2-1734054039648.png

 

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"

1 ACCEPTED SOLUTION

@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:

NickParsons_0-1734309474354.png

 

View solution in original post

17 REPLIES 17

Ankur Bawiskar
Tera Patron
Tera Patron

@Moedeb 

try this

var str = inputs.full_comment;
var dateRE = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/;
str = str.replace(dateRE, '');
outputs.comment = str;

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

@Ankur Bawiskar thank you for the idea, unfortunately I'm getting no text coming through via the output.

As you can see from the following, it is getting the full text, but for some reason is either blanking the text and passing nothing, or it's not actually passing correctly?

 

Moedeb_0-1734060997337.png

 

I have an output set as follows:

Moedeb_1-1734061207508.pngMoedeb_2-1734061226896.pngMoedeb_3-1734061258371.png

 

Hey, are you able to share what Step 1 does?
Can you also try using your original script, but use `.toString()` like this `inputs.full_comment.toString()`?

Hi @Nick Parsons thanks for the reply.

I have tried tostring previously without any success.

 

As for step one, it is simply lookup record - looking for the approval related to the input RITM