Push approval comments on catalog task variable

Ankita Gupte
Kilo Sage

I am trying to push approval comments of particular stage to catalog task variable.

 

So the requirement is if the RITM stage IT Security approval is approved with comments then the comments of this stage should be populated on catalog task variable.

 

I have added below script to workflow activity of catalog task which I found on community forum

var arr = [];
var apv = new GlideRecord('sysapproval_approver');
apv.addQuery('sysapproval', current.sys_id);
apv.addQuery('comments', '!=', ''); // Only find approvals that have comments on them
apv.query();
while (apv.next()) { // Go through all approvals with comments
arr.push("Approval Comments: from " + apv.approver.name + "\n" + apv.comments.getJournalEntry(-1));
}
task.work_notes = arr.join('\n');

 

But how to add RITM stage check if the approval comments are on IT Security approval users and populate it on catalog task variable on that particular catalog task.

1 ACCEPTED SOLUTION

Amit Gujarathi
Giga Sage
Giga Sage

HI @Ankita Gupte ,
I trust you are doing great .
Please find the updated code for the same.

var arr = [];
var apv = new GlideRecord('sysapproval_approver');
apv.addQuery('sysapproval', current.sys_id);
apv.addQuery('stage', 'IT Security'); // Check for the IT Security stage
apv.addQuery('state', 'approved'); // Only consider approved stages
apv.addQuery('comments', '!=', ''); // Only find approvals that have comments
apv.query();

while (apv.next()) {
    // Go through all approvals with comments from IT Security stage
    arr.push("Approval Comments: from " + apv.approver.getDisplayValue() + "\n" + apv.comments.getJournalEntry(-1));
}

// Assuming 'task' is the catalog task GlideRecord and 'your_variable_name' is the name of your variable
var taskGr = new GlideRecord('sc_task');
taskGr.get(task.sys_id); // Retrieve the specific catalog task
taskGr.setValue('your_variable_name', arr.join('\n')); // Set the variable with the comments
taskGr.update();

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



View solution in original post

7 REPLIES 7

Brad Bowman
Kilo Patron
Kilo Patron

If you're looking for only a certain approval record out of those with comments associated with the same RITM, then you'll have to add an addQuery line that uniquely identifies this record - is a certain user or group assigned to this approval?  Or you can order the results by created_on, if this approval would be the first or last created.  Or use setLimit to only return the first three approval records that were created, if this one is the third or whatever out of more than that.

Ankita Gupte
Kilo Sage

Hi Brad, Thank you for response.

 

Appreciate if you could help to modify the above script for adding query, The approval group name is IT Security group, so if the approval comments are added by any one group member from IT security group then only it should populate on catalog task work notes and catalog task variable named "approval comments".

When you create a group approval, there is an out of box business rule that processes the record on the sysapproval_group table, and creates a record on the sysapproval_approver table for each member of the group.  These records have the group field populated, which is a reference to the sysapproval_group approval record.  Because of this, all you need to add to your query is this line before apv.query()

apv.addQuery('group.assignment_group.name', 'IT Security group');

 

Hi Brad, 

 

Thank you for the above, its working fine. Really appreciate the support.

 

I also wanted to know if we can update the approval comments on catalog task variable?