Flow Designer - Ask For Approval Action - How to Access Created Approval

aen612
Tera Guru

I need to access a group approval record that was created in Flow Designer using the 'Ask For Approval' action in a following step.

 

I'm creating a group approval record (sysapproval_group) in a flow using the 'Ask For Approval' action. Calling a subflow to create the approval with Wait For Completion = false (I need to create multiple approvals simultaneously, each group approval has no impact on another). After the group approval is created I need to update the corresponding automatically created individual approvals (sysapproval_approver) with some instructions in a custom field.

calling_subflow.png

 

I'm not sure how to look up the group record. Using the pill picker in a following step only shows 'Approval State', 'Action Status', and 'Don't Treat as Error'. I need to access the Number or the sys_id of the group approval record.

wait_set_variable.png

approval_options.png

 

 


I can look up the group approval record by assignment group and/or the parent field (item being approved) but in my use case these aren't guaranteed to be unique combinations. If I limit the created timeframe (sys_created_onONLast 15 minutes) and search, the result should be the one I'm looking for but it's not guaranteed.

 

Does anyone know how to access an approval record that was created in Flow Designer using the 'Ask For Approval' action in a following step? The group approval records themselves don't have the flow context or anything like that that I've been able to find.

1 ACCEPTED SOLUTION

aen612
Tera Guru

For now, I'm settling for finding Group Approvals (sysapproval_group) that were created in the past or current minute and assigned to a given assignment group and approving a given AD group. This is working as expected, not 100% ideal but close enough, for now.

var findApprovalRecord = 'not what we want';
var groupApprovalRecord = new GlideRecord('sysapproval_group');
groupApprovalRecord.addEncodedQuery('assignment_group=' + fd_data.flow_var.input_approval_group + '^parent=' + fd_data.flow_var.input_ad_group + '^sys_created_onONLast minute@javascript:gs.beginningOfLastMinute()@javascript:gs.endOfLastMinute()^ORsys_created_onONCurrent minute@javascript:gs.beginningOfCurrentMinute()@javascript:gs.endOfCurrentMinute()');
groupApprovalRecord.query();
if(groupApprovalRecord.next()){
findApprovalRecord = groupApprovalRecord.getValue('sys_id');
}
return findApprovalRecord;

 

Then, performing a 'Look Up Records' action on sysapproval_approver where 'group.sys_id' matches findApprovalRecord (group approval sys_id) from above. Finally, looping through these records updating the custom notes to approver field.
approval_subflow_done-ish.png

View solution in original post

7 REPLIES 7

aen612
Tera Guru

For now, I'm settling for finding Group Approvals (sysapproval_group) that were created in the past or current minute and assigned to a given assignment group and approving a given AD group. This is working as expected, not 100% ideal but close enough, for now.

var findApprovalRecord = 'not what we want';
var groupApprovalRecord = new GlideRecord('sysapproval_group');
groupApprovalRecord.addEncodedQuery('assignment_group=' + fd_data.flow_var.input_approval_group + '^parent=' + fd_data.flow_var.input_ad_group + '^sys_created_onONLast minute@javascript:gs.beginningOfLastMinute()@javascript:gs.endOfLastMinute()^ORsys_created_onONCurrent minute@javascript:gs.beginningOfCurrentMinute()@javascript:gs.endOfCurrentMinute()');
groupApprovalRecord.query();
if(groupApprovalRecord.next()){
findApprovalRecord = groupApprovalRecord.getValue('sys_id');
}
return findApprovalRecord;

 

Then, performing a 'Look Up Records' action on sysapproval_approver where 'group.sys_id' matches findApprovalRecord (group approval sys_id) from above. Finally, looping through these records updating the custom notes to approver field.
approval_subflow_done-ish.png

aen612
Tera Guru

I ended up creating a support request to ServiceNow and they confirmed that there is not a way to accomplish what I wanted to do, so the query above is the best/only approach.

sabarni
Tera Contributor

Hi @aen612 , I am trying something very similar. Can you please let me know where you are scripting this?

 

Thanks in advance.