Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Adding Approval Comments to Catalog Item RITM Description

tgcorbin
Mega Contributor

Hello, 

For a requirement on a Catalog Item, I need to add the comments from an approval to the RITM description.  I will post an image of the current flow and script below, but I am running into an issue. 

The script works for the first few approvals, but for approvals 3-5, it pulls comments from previous approvals, not the current one. 

Any help would be appreciated, thanks.

find_real_file.png

var appStatus; 
var appApprover; 
var appComments; 

workflow.scratchpad.comments = ''; 

var app = new GlideRecord('sysapproval_approver'); app.addQuery('sysapproval', current.sys_id); app.query(); 

while(app.next()){ 
    appStatus= "Approval Status: " + app.state + "\n";
    appApprover= "Approver: "+
app.approver.getDisplayValue() + "\n";
    appComments= app.comments.getJournalEntry(-1); 
} 

workflow.scratchpad.comments += appStatus;
workflow.scratchpad.comments += appApprover;
workflow.scratchpad.comments += appComments; 

var comments = workflow.scratchpad.comments; current.description += comments;
 
var screquest = new GlideRecord('sc_request'); screquest.get(current.request); 
screquest.description = desc; 
screquest.update();
1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

add orderByDesc in your query

var app = new GlideRecord('sysapproval_approver');

app.addQuery('sysapproval', current.sys_id);

app.orderByDesc('sys_updated_on'); 

app.query();

View solution in original post

2 REPLIES 2

Mike Patel
Tera Sage

add orderByDesc in your query

var app = new GlideRecord('sysapproval_approver');

app.addQuery('sysapproval', current.sys_id);

app.orderByDesc('sys_updated_on'); 

app.query();

orderByDesc ended up only pulling the first list of comments, but I changed it to orderBy and it is pulling the last comment which is what I need.  Thank you for pointing me in the right direction, you're a hero!