- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2025 10:54 PM
Hi Community,
I’m working on a use case in Flow Designer where I need to programmatically track and cancel a flow execution that created approval records.
Scenario:
When a dmn_demand moves from Screening to Qualified, a Flow Designer flow ("Create Approval for Tech Demand") generates approval records (using the Ask for Approval action) for all users in the related Portfolio group.
If the Portfolio group is updated on the Demand because the initial group was incorrect, another flow ("Update Approvals for Tech Demand") is triggered to:
Mark existing approvals as No Longer Required, and
Generate a new set of approvals for the updated group.
Problem:
The original flow ("Create Approval for Tech Demand") stays stuck waiting. This is because the approval state being set to No Longer Required doesn’t satisfy the Approve/Reject condition that allows the flow to proceed.
I need to reliably:
Trace back from a given sysapproval_approver record to the sys_flow_execution that created it.
Cancel that flow execution to prevent it hanging indefinitely on the Ask for Approval step.
What I’ve tried so far:
Added a custom field (u_generated_from) on sysapproval_approver.
- Wrote a Business Rule on insert of approval records that looks up the most recent sys_flow_execution record in sys_flow_context / sys_hub_flow_context to populate u_generated_from.
- The issue is that there’s no direct reference between sys_flow_execution and the approval record, so my approach only works intermittently.
Here's the Business Rule:
(function executeRule(current, previous /*null when async*/) {
gs.sleep(10000);
if (gs.getSession().isInteractive() == false) {
gs.info("Approval Tracking: Starting population for approval: " + current.sys_id);
var contextGR = new GlideRecord('sys_flow_context');
contextGR.addQuery('state', 'WAITING');
contextGR.orderByDesc('sys_created_on');
contextGR.query();
if (contextGR.next()) {
gs.info("Approval Tracking: Found flow context: " + contextGR.sys_id + " for approval: " + current.sys_id);
current.u_generated_from = contextGR.sys_id;
} else {
gs.warn("Approval Tracking: No active flow context found for approval: " + current.sys_id);
}
} else {
gs.info("Approval Tracking: Skipping population for interactive session (approval: " + current.sys_id + ")");
}
})(current, previous);
Questions for the community:
- Is there a reliable way to capture and store the sys_id of the flow execution that created an approval record?
- Given a sys_flow_execution.sys_id, is there an out-of-the-box API or pattern to cancel the flow cleanly (e.g., via FlowAPI, FlowRuntime or directly from sys_flow_execution)?
- Has anyone built a reusable pattern for tracking approval-generating flows and cancelling them mid-execution?
We’re currently on Xanadu (upgrading to Yokohama in 2 weeks). The use case is specific to Demands for now, but we’d like to generalise this to all approval records in future.
Would love to hear from anyone who’s dug into sys_flow_execution, sys_flow_context, or sys_hub_flow_context for similar use cases.
Thanks,
Jasmin
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2025 07:01 PM
Instead of setting the 'old' approval to "No longer required", cancelling it will allow the "Ask for Approval" step to proceed, thus being able to continue the flow. Tracking of the "Generated From" flow ID no longer required (for this use case).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2025 07:01 PM
Instead of setting the 'old' approval to "No longer required", cancelling it will allow the "Ask for Approval" step to proceed, thus being able to continue the flow. Tracking of the "Generated From" flow ID no longer required (for this use case).