|
| 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 following script to your ServiceNow instance as a UI Action: |
| 28 | + |
| 29 | +```javascript |
| 30 | + |
| 31 | +function cancelRunningFlows() { |
| 32 | + |
| 33 | + try { |
| 34 | + var grFlowExecution = new GlideRecord("sys_flow_context"); |
| 35 | + grFlowExecution.addQuery("source_record", current.sys_id); |
| 36 | + grFlowExecution.query(); |
| 37 | + |
| 38 | + while (grFlowExecution.next()) { |
| 39 | + sn_fd.FlowAPI.cancel(grFlowExecution.getUniqueValue(), "Canceling Flows"); |
| 40 | + } |
| 41 | + } catch (error) { |
| 42 | + gs.error("Error cancelling flows: " + error.message); |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | + |
| 47 | +``` |
| 48 | + |
| 49 | +### Example Usage |
| 50 | + |
| 51 | +1. Open the record where you want to cancel the associated flows. |
| 52 | +2. Click on the **Cancel Flow** UI Action button. |
| 53 | +3. The system will identify and cancel all running flows for the current record. |
| 54 | + |
| 55 | + |
| 56 | +## Dependencies |
| 57 | + |
| 58 | +- `sn_fd.FlowAPI` |
| 59 | + |
| 60 | +## Category |
| 61 | + |
| 62 | +Client-Side Components / UI Actions |
0 commit comments