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

Chaitanya ILCR
Kilo Patron

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

Amit Verma
Kilo Patron
Kilo Patron

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.

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

Moedeb_0-1734069524191.png

 

Moedeb_1-1734069542835.pngMoedeb_2-1734069590426.png

 

Moedeb_3-1734069609469.png