Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Get Sys ID of Approval Record Generated From Approval - User Activity

codedude
Mega Expert

I have an approval user activity in my workflow. I am dynamically generating the approvers in the additional approver script. I am trying to get the sys_id of each approval record that is generated as it is generated via the script and storing it else where (weird I know). I will post my script below and place comments where I am thinking this should be executed.

var answer = [];

var sys_ids = [];

var grReqItem = new GlideRecord('sc_req_item');

grReqItem.addQuery('request',current.sys_id);

grReqItem.query();

while(grReqItem.next())

{

  var selectedZones = grReqItem.variable_pool.zone_access.toString();

  var individualZones = selectedZones.split(",");

  for(var i = 0; i < individualZones.length; i++)

  {

            var grZoneManager = new GlideRecord('zones');

            grZoneManager.addQuery('sys_id', individualZones[i]);

            grZoneManager.query();

            while(grZoneManager.next())

            {

                      answer.push(grZoneManager.u_primary_zone_manager);

                      //I think it should be done here

                      sys_ids.push(/*Push the sys ids of the approval record that was just pushed on the line above*/)

            }

  }

}

1 ACCEPTED SOLUTION

Turns out the approval record is not created until the entire activity is finished. So I had to add a timer for that runs the same time as the approval activity and then add a run script to capture the sys_id.


View solution in original post

7 REPLIES 7

Abhinay Erra
Giga Sage

What is the requirement here?


Turns out the approval record is not created until the entire activity is finished. So I had to add a timer for that runs the same time as the approval activity and then add a run script to capture the sys_id.


Hello,

 

Can you please let me know how to get approval sys_id in the next run script activity? Is it again by querying the Approvals table? But how to get exact approval sys_id which was generated in previous activity?

 

Quick response will be much appreciated