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

So you want to get all the sys_id's of the approval records?


That is correct. I want to retrieve each sys_id of the approval record as it is created via the approval user activity.


You will need a run script activity after the approval user activity and put this script in there



var arr=[];


var gr= new GlideRecord('sysapproval_approver');


gr.addQuery('sysapproval',current.sys_id);


gr.query();


while(gr.next()){


arr.push(gr.getValue('sys_id')); //this will contain all the sys_id


}


Yeah... I know that way, but is a little too much brute force.



The way I am reading this is that it will give me the complete list of approvals. I am wanting to grab them one by one so I can make a reference for each individual approval record for that request.



That is why I am wanting to get the sys_id as it is created in the approval activity.