Description
Hello everyone,
I’d like to share about the Cancellation Scope activity in UiPath, one of the latest activities I’ve experienced, which is not yet very popular.
If you want to have your UiPath process enter a specific workflow when it is stopped from UiPath Studio or UiPath Assistant -without using Orchestrator- you can use the CancellationScope activity. This activity allows you to define a cancellation handler that executes when the process is canceled.
Here’s how you can implement this:
Open Your Main Workflow:
Open your Main.xaml file in UiPath Studio where your main process logic resides.
Use a CancellationScope Activity:
Drag and drop a CancellationScope activity onto your workflow designer surface.
Place it so that it encompasses the main part of your process that you want to monitor for cancellation.
Configure the CancellationScope:
The CancellationScope activity has two main sections: Body and CancellationHandler.
In the Body:
Place all the activities that constitute your main process logic inside the Body section of the CancellationScope.
In the CancellationHandler:
Drag and drop an Invoke Workflow File activity (or any other activity that represents the specific workflow you want to execute upon cancellation).
Set the WorkflowFileName property to the path of your specific workflow.
- If you have exception handling in your process, make sure to adjust it so that exceptions within the CancellationScope are properly handled.
Test Your Process:
Run your process from UiPath Studio or UiPath Assistant.
While the process is running, click the Stop button.
Verify that your specific workflow is executed as defined in the CancellationHandler.
CancellationScope Activity:
The CancellationScope activity is designed to handle cancellation requests gracefully.
When a cancellation is triggered (by clicking Stop), the activities within the Body are canceled, and the CancellationHandler is executed.
Why This Works Without Orchestrator:
The CancellationScope does not rely on Orchestrator; it responds to the cancellation token that is triggered when you stop the process from Studio or Assistant.
This allows you to intercept the cancellation and perform any necessary actions, such as invoking a specific workflow.
Note: Be aware that if your activities within the Body do not check for cancellation (e.g., long-running loops without delay or check), they might not cancel immediately.
Testing:
Thoroughly test your cancellation handling to ensure it behaves as expected in different scenarios.
Exception Handling:
If you have existing Try-Catch blocks, ensure that they do not inadvertently swallow the cancellation exceptions, preventing the CancellationHandler from executing.
By wrapping your main process within a CancellationScope and defining a CancellationHandler, you can ensure that a specific workflow is executed whenever the process is stopped from UiPath Studio or UiPath Assistant, even without using Orchestrator.
Happy automation!
If you want to explore more topics about UiPath, check out:
Link
Date
2024-11-12
Related UiPath products
Assistant
Robot
Studio
Studio Web