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

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



Amazing Amit. This is working perfectly fine. Thank you so much.

Thank you Brad for your support as well!

Really appreciate your responses.

Hi Amit,

 

There is little change in requirement, we have to populate approval comments based on RITM stage.

So the approval comment entered for "IT Security" Stage that comments should populate. 

so I have modified script as below hightlighted in bold, but it is taking all approval comments for other approval stages as well. Am I missing something here, Please advice.

 

var arr = [];
var apv = new GlideRecord('sysapproval_approver');
apv.addQuery('sysapproval', current.sys_id);
apv.addQuery('sysapproval.stage', 'IT Security');
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');
 
// 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('u_approval_comment', arr.join('\n')); // Set the variable with the comments
taskGr.update();