Parallel flow -> multiple Approval Activity skipping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2017 01:43 PM
Here's my use case:
When a new record is added to pc_software_cat_item run an Approval Activity for each Company using our instance. If approved the item is added to their employee user criteria so that it becomes available in Portal. Each company can choose to approve or deny and they're independent of each other.
The issue:
I can create ~20 stand-alone workflows (1 per company) and it works, however, ideally this would be dynamic and just need 1 workflow that accepts param's for the approval group and user criteria record.
This seemed like a good use case for Parallel Flow so I created a workflow (New Catalog Item Approval - Parent) that runs a Parallel Flow Launcher for my approval workflow (New Catalog Item Approval). I'm triggering this with an on-after business rule and passing an input with the array containing an approval group and the user criteria record from the parent workflow to the approval workflow. This works and the inputs are correctly passed, however, only 1 instance of the approval activity will hold 'executing' and the rest just skip (attached). The skipped workflows are receiving correct inputs.
I added the timer, which does seem to occasionally allow more than 1 flow to stay executing but I have no idea why that helps.
Any idea's why this is failing?
- Labels:
-
Scripting and Coding
- 5,133 Views

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2018 04:17 PM
LOL, guess I should have someone audit my code before posting.
I check the instance and the code does have the space between the var and j. Might have gotten removed during my cut/paste and formatting.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2019 09:26 AM
For future community users-
I have faced the same issue with subflow approval activity getting skipped. Putting a timer before launching the activity magically resolved the issue.
Try to put a timer before launching parallel flow and before approval activity.
PS- Mark the answer correct or helpful as applicable.
Thanks
Purbali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2019 02:24 AM
a simple 2 second wait helped me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2021 01:59 PM
I know this is an old issue but the solution proposed here did not work for me. Having to build custom script to create tasks and approvals and then another script to handle the result seems to much of an overhead to me.
The timer workaround worked most of the time, but not always. Following investigation of the code, this is because of a race condition, without the timer, the parallel flows are actually launched sequentially one after the other. Since the task/approval for that workflow version already exists it reuses it instead of creating a new one (a bit different for approval but same concept). Therefore when you put the timer, you introduce a case where both workflow will be launched in parallel therefore when the script checks for an existing task/approval it does not exist yet. However you are not guaranteed your timer will run in parallel, one might run after the other completed and therefore you again have the issue with your task/approval, and that randomly.
The root cause is that to identify the task/approval, the scripts are using the wf_activity field. That field refers to the activity of the worfklow version, therefore is not unique across workflow instances (context).
To have a reliable solution, I decided to customize 3 scripts that were relevant to me (there are other script using that pattern but they did not touch me so I left them untouched).
- Workflow Activity Definition: Approval - Group
- Workflow Activity Definition: Approval - User
- Script Include: WFCreateTaskActivityUtils
Ideally this would be fixed by ServiceNow but since the Workflows are in end of life and ServiceNow is moving to Flow Designer, I did not have much hope to have this fixed and don't expect much maintenance to be required since they probably won't make evolutions on these scripts.
Customization
Custom field
To start, create a custom reference field named Workflow context (u_wf_context) on the task table and sysapproval_approver tables. OOB the wf_activity is set to inactive, you can also set that field to inactive to avoid it being used in lists and reports. Make sure to validate your default form layout are not affected by this new field.
Workflow Activity Definition: Approval - Group
At line 145, add the script line with the comment:
...
gr.addQuery('wf_activity', activity.activity.sys_id);
gr.addQuery('u_wf_context', activity.context.sys_id); // Custom fix for parallel flow launcher
gr.addQuery('approval', '!=', 'cancelled');
...
At line 223, add the script line with the comment:
...
approval.wf_activity = activity.activity.sys_id;
approval.u_wf_context = activity.context.sys_id; // Custom fix for parallel flow launcher
approval.approval = state;
...
Workflow Activity Definition: Approval - User
At line 144, add the script line with the comment:
...
gr.addQuery('wf_activity', activity.activity.sys_id);
gr.addQuery('u_wf_context', activity.context.sys_id); // Custom fix for parallel flow launcher
gr.addQuery('approval', '!=', 'cancelled');
...
At line 244, add the script line with the comment:
...
approval.wf_activity = activity.activity.sys_id;
approval.u_wf_context = activity.context.sys_id; // Custom fix for parallel flow launcher
approval.approval = state;
...
Script Include: WFCreateTaskActivityUtils
At line 27, add the script line with the comment:
...
task.addQuery('wf_activity', activity.activity.sys_id);
task.addQuery('u_wf_context', activity.context.sys_id); // Custom fix for parallel flow
task.query();
...
At line 86, add the script line with the comment:
...
task.wf_activity = activity.activity.sys_id;
task.u_wf_context = activity.context.sys_id; // Custom fix for parallel flow launcher
return task.insertOrUpdate('sys_id');
...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2021 11:30 AM
Hi Laurent,
I have a couple of questions regarding your customizations:
1. For the custom fields, do they reference Workflow Activity like the OOB Workflow activity field?
2. Will customizing WFCreateTaskActivityUtils work for Catalog Task and Create Task workflow activities?
I really like this approach and want to make sure I'm doing things correctly.
Regards,
Kent