From 0ee4c26aabd0920dabd78f5d28728e8d6ab2abae Mon Sep 17 00:00:00 2001 From: Nilesh Wahule <77268537+Its-Nmk@users.noreply.github.com> Date: Wed, 22 Oct 2025 19:33:28 +0530 Subject: [PATCH 1/5] Add README for CancelFlow UI Action Added documentation for the CancelFlow UI Action, detailing its purpose, functionality, usage instructions, and dependencies. --- .../Cancel Flow Executions/README.md | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Client-Side Components/UI Actions/Cancel Flow Executions/README.md diff --git a/Client-Side Components/UI Actions/Cancel Flow Executions/README.md b/Client-Side Components/UI Actions/Cancel Flow Executions/README.md new file mode 100644 index 0000000000..622b22b7dd --- /dev/null +++ b/Client-Side Components/UI Actions/Cancel Flow Executions/README.md @@ -0,0 +1,62 @@ +# CancelFlow UI Action + +A ServiceNow utility that dynamically cancels flows associated with the current record, ensuring seamless process management. + +## Challenge + +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. + +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. + +## Description + +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. + +## Functionality + +The CancelFlow UI Action provides the following capabilities: +- Dynamically identifies running flows for the current record. +- Cancels the identified flows programmatically. +- Displays success or error messages to the user for better visibility. +- Ensures smooth handling of flow cancellations without manual intervention. + +## Usage Instructions + +### UI Action Script + +Add the following script to your ServiceNow instance as a UI Action: + +```javascript + +function cancelRunningFlows() { + + try { + var grFlowExecution = new GlideRecord("sys_flow_context"); + grFlowExecution.addQuery("source_record", current.sys_id); + grFlowExecution.query(); + + while (grFlowExecution.next()) { + sn_fd.FlowAPI.cancel(grFlowExecution.getUniqueValue(), "Canceling Flows"); + } + } catch (error) { + gs.error("Error cancelling flows: " + error.message); + } +} + + +``` + +### Example Usage + +1. Open the record where you want to cancel the associated flows. +2. Click on the **Cancel Flow** UI Action button. +3. The system will identify and cancel all running flows for the current record. + + +## Dependencies + +- `sn_fd.FlowAPI` + +## Category + +Client-Side Components / UI Actions From 46c7c391808c4e6f0b0ad959f624d2a1bab56012 Mon Sep 17 00:00:00 2001 From: Nilesh Wahule <77268537+Its-Nmk@users.noreply.github.com> Date: Wed, 22 Oct 2025 19:34:20 +0530 Subject: [PATCH 2/5] Add function to cancel running flow executions --- .../Cancel Flow Executions/cancelFlow.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Client-Side Components/UI Actions/Cancel Flow Executions/cancelFlow.js diff --git a/Client-Side Components/UI Actions/Cancel Flow Executions/cancelFlow.js b/Client-Side Components/UI Actions/Cancel Flow Executions/cancelFlow.js new file mode 100644 index 0000000000..7ae3f7d0d8 --- /dev/null +++ b/Client-Side Components/UI Actions/Cancel Flow Executions/cancelFlow.js @@ -0,0 +1,16 @@ +function cancelRunningFlows() { + + try { + var grFlowExecution = new GlideRecord("sys_flow_context"); + grFlowExecution.addQuery("source_record", current.sys_id); + grFlowExecution.query(); + + while (grFlowExecution.next()) { + sn_fd.FlowAPI.cancel(grFlowExecution.getUniqueValue(), "Canceling Flows"); + } + } catch (error) { + gs.error("Error cancelling flows: " + error.message); + } +} + + From f4215929d67db3362ff2031ad4bf4aad6673271d Mon Sep 17 00:00:00 2001 From: Nilesh Wahule <77268537+Its-Nmk@users.noreply.github.com> Date: Wed, 22 Oct 2025 19:36:14 +0530 Subject: [PATCH 3/5] Update README to include Business rules usage Added information about using the cancel action in Business rules. --- .../UI Actions/Cancel Flow Executions/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Client-Side Components/UI Actions/Cancel Flow Executions/README.md b/Client-Side Components/UI Actions/Cancel Flow Executions/README.md index 622b22b7dd..7dc00247c6 100644 --- a/Client-Side Components/UI Actions/Cancel Flow Executions/README.md +++ b/Client-Side Components/UI Actions/Cancel Flow Executions/README.md @@ -51,6 +51,7 @@ function cancelRunningFlows() { 1. Open the record where you want to cancel the associated flows. 2. Click on the **Cancel Flow** UI Action button. 3. The system will identify and cancel all running flows for the current record. +4. The same can be used in Business rules as well based on trigger conditions ## Dependencies From 959b848828910af788519fa7bd29fe47a36f43eb Mon Sep 17 00:00:00 2001 From: Nilesh Wahule <77268537+Its-Nmk@users.noreply.github.com> Date: Wed, 22 Oct 2025 20:00:47 +0530 Subject: [PATCH 4/5] Revise UI Action script instructions in README Updated usage instructions for the UI Action script. --- .../Cancel Flow Executions/README.md | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/Client-Side Components/UI Actions/Cancel Flow Executions/README.md b/Client-Side Components/UI Actions/Cancel Flow Executions/README.md index 7dc00247c6..e1ded2d4ac 100644 --- a/Client-Side Components/UI Actions/Cancel Flow Executions/README.md +++ b/Client-Side Components/UI Actions/Cancel Flow Executions/README.md @@ -24,27 +24,8 @@ The CancelFlow UI Action provides the following capabilities: ### UI Action Script -Add the following script to your ServiceNow instance as a UI Action: +Add the given script to your UI Action: -```javascript - -function cancelRunningFlows() { - - try { - var grFlowExecution = new GlideRecord("sys_flow_context"); - grFlowExecution.addQuery("source_record", current.sys_id); - grFlowExecution.query(); - - while (grFlowExecution.next()) { - sn_fd.FlowAPI.cancel(grFlowExecution.getUniqueValue(), "Canceling Flows"); - } - } catch (error) { - gs.error("Error cancelling flows: " + error.message); - } -} - - -``` ### Example Usage From 6909766af306364f2e251663966283a9ebf26c3d Mon Sep 17 00:00:00 2001 From: Nilesh Wahule <77268537+Its-Nmk@users.noreply.github.com> Date: Wed, 22 Oct 2025 23:37:22 +0530 Subject: [PATCH 5/5] 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. --- .../UI Actions/Cancel Flow Executions/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Client-Side Components/UI Actions/Cancel Flow Executions/README.md b/Client-Side Components/UI Actions/Cancel Flow Executions/README.md index e1ded2d4ac..c02c24b681 100644 --- a/Client-Side Components/UI Actions/Cancel Flow Executions/README.md +++ b/Client-Side Components/UI Actions/Cancel Flow Executions/README.md @@ -35,6 +35,11 @@ Add the given script to your UI Action: 4. The same can be used in Business rules as well based on trigger conditions +### Visibility for UI Action + +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. + + ## Dependencies - `sn_fd.FlowAPI`