Copy users from run script and send approval notifications to copied users

Jay N
Tera Contributor

Hi Experts,

 

We have an requirement to send approval notifications to users returned via runscript in worflow, can you please help me with the solution/code.

Run script code:

var usr = [];
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.addQuery('sys_id', current.sys_id);
 
//ritmGr.addQuery('sys_id', '7fe92abd1b2246dc577f6287624bcb96');
ritmGr.query();
 
if (ritmGr.next()) {
    for (var i = 0; i < ritmGr.variables.mrvs_dcom_select_servers.getRowCount(); i++) {
 
        gs.info('Jay kkk ' + ritmGr.variables.mrvs_dcom_select_servers.mrvs_dcom_select_a_server[i]);
        //gs.info('kkk');
 
        var grRel = new GlideRecord('cmdb_rel_ci');
        //grRel.addEncodedQuery('parent.sys_class_name=cmdb_ci_service^type=1a9cb166f1571100a92eb60da2bce5c5^child=36aa72161b719918af1f3224cc4bcb7e');
        grRel.addEncodedQuery('parent.sys_class_name=cmdb_ci_service^type=1a9cb166f1571100a92eb60da2bce5c5^child=' + ritmGr.variables.mrvs_dcom_select_servers.mrvs_dcom_select_a_server[i]);
        grRel.query();
 
        while (grRel.next()) {
            //gs.info('Jay jjj ' + grRel.parent.u_cmdb_business_owner.email.toString());
usr.push(grRel.parent.assigned_to.email.toString());
usr.push(grRel.parent.u_cmdb_business_owner.email.toString());
usr.push(grRel.parent.u_operations_manager.email.toString());
 
        }
    }
}
//gs.eventQueue('notify.service.owners', current, usr.toString()); // ritm table notification
gs.eventQueue('approval.inserted', current, usr.toString())//approval.inserted (sys_approval table notification)
 
Requirement is users are already captured in "usr" array, now we need to send approval notifications.
 
JayN_0-1717693471164.png

 

 
Thanks, Jay
 
1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

It's best to do this in the script of the Approval - User activity, so that the usr array is the approvers array.  If you must keep it separate for some reason, 'usr' must contain sys_ids from the sys_user table, not email addresses.  Once you have that array, copy it to a scratchpad variable

workflow.scratchpad.usrArr = usr.join(',');

 Then in the Approval - User activity script, you can populate the approval array from the scratchpad variable, which is already a comma-separated string

answer = workflow.scratchpad.usrArr;