generate a catalog task for whoever on the group approves the request item

TalitaA
Tera Contributor

I need to generate a task and assigned to whoever approves the request item. I'm having a hard time to retriever the approver from the approver table [sysapprover_approver] and set on "assigned to" on catalog task 

2 REPLIES 2

mattmm
Kilo Sage

@TalitaA Have you considered a Business Rule on the sysapproval_approver table?

When: After

Tick Update

Filter condition/s: state changes to approved....or you can do approval = requested (depending on where you want it to occur)

Script:

(function executeRule(current, previous) {

    // Only continue if the approval is for a Requested Item
    if (current.sysapproval.getTableName() !== 'sc_req_item') {
        return;
    }

    // Get the approved RITM
    var ritm = current.sysapproval.getRefRecord();

    // Sanity check
    if (!ritm || !current.approver) {
        return;
    }

    // Query Catalog Tasks linked to the RITM
    var taskGR = new GlideRecord('sc_task');
    taskGR.addQuery('request_item', ritm.sys_id);
    // Optional: Only assign if task doesn't already have someone
    // taskGR.addNullQuery('assigned_to');
    taskGR.query();

    while (taskGR.next()) {
        taskGR.assigned_to = current.approver;
        taskGR.update();
    }

})(current, previous);

 

Ankur Bawiskar
Tera Patron
Tera Patron

@TalitaA 

you can use Lookup Record and not Lookup Records

The output from Lookup Record will be sysapproval_approver record

From there you can select the Approver field and set in Assigned To field on Catalog Task

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader