Custom Flow Action: Create Group Approvals not Working Quite Right
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
We are buiding a process where users can fill out a Multi Row Variable Set (MRVS), and from that, we will build Group Approvals. The MRVS only has two fields: Approval Group to assign to, and Comments.
I am building a Flow to create Group Approvals for each record entered into the MRVS. Related to that, I am trying to build a Custom Action that will do the following:
1. Create the Group Approval
2. After step 1, loop through all the related records in the sysapproval_approver table to update the Comments field along with a custom Approval Type field we have on this table.
Here is the script I have:
(function execute(inputs, outputs) {
//initialize Group Approval sys_id
var ga_sys_id = '';
//insert new record into Group Approval table
var approvalGR = new GlideRecord("sysapproval_group");
approvalGR.initialize();
approvalGR.parent = inputs.ritm_sys_id;
approvalGR.assignment_group = inputs.app_grp;
approvalGR.approval = "requested";
approvalGR.wait_for = 'any';
var newSysID = approvalGR.insert();
//get number of new Group Approval record
if(newSysID){
var approvalGR2 = new GlideRecord("sysapproval_group");
if(approvalGR2.get(newSysID)){
//store Group Approval Number
outputs.grp_num = approvalGR2.getValue('number');
//capture group approval record sys_id
ga_sys_id = approvalGR2.sys_id;
}
}
//update approval type and comments on user approvals
var grApp = new GlideRecord("sysapproval_approver");
grApp.addQuery('group',ga_sys_id);
grApp.query();
while(grApp.next()){
grApp.u_approval_type = inputs.app_type;
grApp.comments = inputs.cmnt;
grApp.document_id = inputs.ritm_sys_id;
grApp.sysapproval = inputs.ritm_sys_id;
grApp.approval_column = 'approval';
grApp.approval_journal_column ="approval_history";
grApp.update();
}
})(inputs, outputs);
It all seems to work properly in that it creates the Group Approval records, and updates each related record in the sysapproval_approver table, like I expect. However, the behavior of these created records is not quite right. I want to to behave that only one person needs to approve/reject each Group Approval. Then, all the other sysapproval_approver records related to that particular Group Approval are marked as "No longer required". However, this doesn't do that. All the other records are still left as "Requested".
I tried to go back and emulate/set all the field values to match the settings for approval records that are created using the built-in OOTB "Ask for Approval" record (which works properly), but I must be missing something, as I cannot get it to behave the same way as this OOTB Action.
I also tried to search to see if I could find what updates all the other records to "No longer required" when one is approved or rejected. I figure if I can find this rule, I can see what it is looking for, and it might be evident what I need to add or adjust to my code. I searched Workflow, Flows, Business Rules, and Client Scripts, and was not able to find it.
Can anyone help?
Either let me know what I need to add/change to my code to allow this "No longer required" functionality to work, or let me know what runs to change the approvals to "No longer required"?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
you should use "Ask for Approval" flow action and have Approval rules (1 approve or all approve etc)
since you are using scripting that logic won't be achievable.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
The issue is that Flow Designer does not support parallel approvals!
I have a dynamic number of approvals (however many number of records there are in the MRVS), and I want to create them all at the same time, so each one isn't waiting on the others to be completed before being created. And they are all Group Approvals.
Maybe this is another one of those more complex things that Flow Designer just cannot handle, and I need to try to use the old Workflow Editor?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
see if these links help, if not then switch to workflow
see these blogs and the KB from ServiceNow
Parallel Approvals in Flow Designer
Parallel Approvals in Flow Designer
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
Hmmm, none of those seem to quite match my situation, with an unknown/dynamic number of approvals. I have a requirements meeting with the team asking for this in the afternoon. Maybe I will see if I can convince them to go in another direction, before I go down this rabbit hole!