Stop activity
Overview
The "Stop activity" feature allows you to stop a workflow at any point in the execution process. This is useful for situations where you need to stop the workflow early.
How to use Stop activity
- Add a stop activity to the workflow
To use the Stop activity feature, simply drag and drop the button "Stop" where you want to stop in the workflow.
- Configure the stop activity
After you drag and drop the stop activity into the workflow, the "Create Activity Definition: Stop" window will be opened.
- Update general information
The General tab: We use this tab to clarify the result after the stop activity ended.
Field name | Field type | Description |
---|---|---|
Name | Text field | Must be unique and meaningful |
Return result | Radio button | The return result of the stop activity |
The return result field:
Value | Description |
---|---|
None | Casewhere will use the current logic i.e. all required activities completed successfully, to determine if the workflow state should be Open or Complete |
Success | Casewhere will set the workflow state to Complete regardless of the state of activities |
Failed | Casewhere will set the workflow state to Open regardless of the state of activities |
- Put navigation logic
The Navigation tab:
Inclusion Logic:
Required Logic:
Examples
We implement a simple workflow to demonstrate how to use the "Stop activity" feature.
We want to create a simple workflow:
- Step 1: Calculate the sum of a, b.
- Step 2: Multiply the sum of a, b if it is larger than 10.
- Step 3: Print the result of step 1 and step 2 and it does not print anything if one of them is null (can understand that if step 2 is not executed, so does step 3).
Ideally, we must stop the workflow after step 1 if the sum of a, b is equal or less than 10. Now let's start the example.
Using stop activity
- Create a workflow
- Assign data class for that workflow
- Create steps and activities
- Activity: Scripted - Name: Sum
A simple script to calculate the sum of a, b.
int a = 10;
int b = 10;
var result = a + b;
ctx.Set("result", result);
- Activity: Scripted - Name: Multiplication
Multiply the sum of a, b with 2.
int result = ctx.Get<int>("result");
int MultipliedResult = result*2;
ctx.Set("MultipliedResult", MultipliedResult);
- Activity: Scripted - Name: Print
Print out the sum of a, b and the multiplication of it with 2 (We use a log warning to print the result).
int result = ctx.Get<int>("result");
int MultipliedResult = ctx.Get<int>("MultipliedResult");
Log.Warning("Sum: {@value1}, Multiplied result: {@value2}", result, MultipliedResult);
- Add condition: Multiplication is executed only if the sum of a, b is greater than 10
- We add a stop activity right after the Activity: Scripted - Name: Sum.
- Set up the inclusion logic for the stop activity: The stop activity is included when the sum is not greater than 10. It means the workflow is stopped if the sum is not greater than 10.
- Set up the return result of the stop activity.
- Add condition: The activity: Scripted - Name: Print is executed only when The activity: Scripted - Name: Multiplication is executed
If the stop activity is included => The workflow is stopped => Both step 2 and step 3 cannot be executed.
If the stop activity is not included => Step 2 is executed => Meet step 3 requirement => Step 3 is executed.
- Create a test run for this workflow
- Run the test
- Check the result in the log viewer
Not using stop activity
If we do not use stop activity, we must implement the navigation rule for step 2 and step 3.
Conclusion
The Stop activity feature is a powerful tool that can help you end a workflow and return the result based on what you choose in General settings (None/Success/Failed). Here are some benefits of using Stop activity:
- We can add rules to stop activity instead of adding rules to many activities
- Return a different result based on the user's choice.
- Easy to maintain: If we add a new activity, we do not need to remember.to implement the navigation rule for that activity to handle the exiting logic in the previous step.
- Visualization: Can see the exiting point easily when generating a visual diagram.