Skip to content

Commit 0908783

Browse files
authored
Cancel running flow executions (#2414)
* Add README for CancelFlow UI Action Added documentation for the CancelFlow UI Action, detailing its purpose, functionality, usage instructions, and dependencies. * Add function to cancel running flow executions * Update README to include Business rules usage Added information about using the cancel action in Business rules. * Revise UI Action script instructions in README Updated usage instructions for the UI Action script. * Enhance README with UI Action visibility guidelines Added section on visibility restrictions for UI Action to ensure only authorized user groups can access the functionality.
1 parent e5fad12 commit 0908783

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# CancelFlow UI Action
2+
3+
A ServiceNow utility that dynamically cancels flows associated with the current record, ensuring seamless process management.
4+
5+
## Challenge
6+
7+
Managing running flows in ServiceNow can be challenging, particularly when multiple flows are tied to a single record. This utility streamlines the process by offering a dynamic solution to identify and cancel running flows, minimizing manual intervention and ensuring seamless operations.
8+
9+
This tool is especially useful in scenarios where you need to halt the current execution and initiate a new flow or process. Additionally, it can be leveraged to forcefully terminate the automation lifecycle when necessary, providing greater control over flow management.
10+
11+
## Description
12+
13+
This UI Action is designed to identify and cancel all running flows associated with the current record in a ServiceNow instance. It provides a user-friendly interface for administrators and developers to manage flow cancellations efficiently. This utility is particularly useful in scenarios where flows need to be terminated to prevent conflicts or errors during record updates.
14+
15+
## Functionality
16+
17+
The CancelFlow UI Action provides the following capabilities:
18+
- Dynamically identifies running flows for the current record.
19+
- Cancels the identified flows programmatically.
20+
- Displays success or error messages to the user for better visibility.
21+
- Ensures smooth handling of flow cancellations without manual intervention.
22+
23+
## Usage Instructions
24+
25+
### UI Action Script
26+
27+
Add the given script to your UI Action:
28+
29+
30+
### Example Usage
31+
32+
1. Open the record where you want to cancel the associated flows.
33+
2. Click on the **Cancel Flow** UI Action button.
34+
3. The system will identify and cancel all running flows for the current record.
35+
4. The same can be used in Business rules as well based on trigger conditions
36+
37+
38+
### Visibility for UI Action
39+
40+
In certain scenarios, it may be necessary to restrict the visibility of this operation to specific user groups. For example, only HR administrators or members of a designated group (e.g., "X Group") should have access to this functionality. These requirements can be addressed by configuring the **Condition** field in the UI Action. You can tailor the conditions to align with your specific use case, ensuring that only authorized users can execute this operation. One edge case about not having an active flow execution can also be handled in the condition which will restrict the visibility if no active flow execution is present.
41+
42+
43+
## Dependencies
44+
45+
- `sn_fd.FlowAPI`
46+
47+
## Category
48+
49+
Client-Side Components / UI Actions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function cancelRunningFlows() {
2+
3+
try {
4+
var grFlowExecution = new GlideRecord("sys_flow_context");
5+
grFlowExecution.addQuery("source_record", current.sys_id);
6+
grFlowExecution.query();
7+
8+
while (grFlowExecution.next()) {
9+
sn_fd.FlowAPI.cancel(grFlowExecution.getUniqueValue(), "Canceling Flows");
10+
}
11+
} catch (error) {
12+
gs.error("Error cancelling flows: " + error.message);
13+
}
14+
}
15+
16+

0 commit comments

Comments
 (0)