How to make the same person as Approver on RITM, who closes the REQTASK in Workflow script?

AbdurRahmanSnow
Giga Guru

Good morning.
On a Catalog Form, I have a Workflow. The requirement is on RITM, whenever the person closes the REQTASK, the same person should be added the Approver on RITM.
How can we do this? Through User Approval - Run script? (Screenshot below). Instead of Group approval, I want the same person who closes the REQTASK to be the approver on RITM, so that, once he approves, the next stages in Workflow proceed.

AbdurRahmanSnow_0-1740374818963.png

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@AbdurRahmanSnow 

you can use user approval activity and use script

answer = [];
var req = new GlideRecord('sc_task');
req.orderByDesc('sys_created_on');
req.addQuery('active', 'false');
req.addQuery('request_item', current.sys_id);
req.setLimit(1);
req.query();
if (req.next()) {
    answer.push(req.closed_by.toString());
}

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

View solution in original post

10 REPLIES 10

Murtaza Saify
Tera Contributor

Using a Business Rule

  1. Create a Business Rule on the sc_task table (which includes REQTASK):

    • Name: Add Approver on RITM when REQTASK is closed

    • Table: Task (sc_task)

    • Advanced: Checked

    • When to run: After

    • Conditions:

      • state changes to Closed

      • sys_class_name is sc_req_item (to ensure it's a REQTASK)

    • Script:

      javascript
      Copy
      (function executeRule(current, previous /*null when async*/) {
          // Get the RITM (Requested Item) record
          var ritm = new GlideRecord('sc_req_item');
          if (ritm.get(current.request_item)) {
              // Add the user who closed the REQTASK as an approver on the RITM
              var approval = new GlideRecord('sysapproval_approver');
              approval.initialize();
              approval.setValue('sysapproval', ritm.sys_id); // Link to RITM
              approval.setValue('approver', current.closed_by); // User who closed the REQTASK
              approval.setValue('state', 'requested'); // Set approval state
              approval.insert();
          }
      })(current, previous);
  2. Activate the Business Rule:

    • Ensure the Business Rule is active and runs in the appropriate scope