When creating workflows (real-time and background) in Dynamics 365 (CRM), you’ll notice there’s a workflow step called “Stop Workflow”. When we add the “Stop Workflow” step as the name suggests, the workflow stops. When stopping the workflow, you can choose one of two options;
- Canceled (Cancelled)
In this article, I would investigate how Dynamics 365 (CRM) behaves when selecting each option.
Let’s create a real-time workflow.
In the first step, I create a new Test record. Then I check a condition. If the value of field Outcome = Success, then I stop the workflow with status of Succeeded. Otherwise, I stop the workflow with status of Canceled.
When workflow stops with status Succeeded, Test record is created. When workflow stops with status Canceled, Test record is NOT created and you’ll see a Business Process Error. The record will NOT be saved due to the error.
Let’s convert the workflow to a background workflow.
I changed the field Outcome to Success and saved the record. Then I changed the Outcome field to Failure and saved the record. Both scenarios worked without any errors. Unlike the real-time workflow, both scenarios created a Test record.
Scenario – Succeeded
Scenario – Canceled
As you can see below, two Test records were created successfully (Notice the time).
Trigger Workflow on Creation of a record
What about triggering the workflow when creating a record. Let’s remove the first step, which created a new record and change the trigger to Record Created.
Create two records with Outcome field set to Success in one and Failure in the other. When the Outcome = Success (i.e. when workflow is stopped with status – Succeeded) record got created. When the Outcome = Failure (i.e. when workflow is stopped with status – Canceled) record creation failed with a Business Process Error.
Create two records with Outcome field set to Success in one and Failure in the other. In both scenarios, records get created.
Stop Workflow step makes Dynamics 365 behave differently on real-time workflow compared to background workflow. While the workflow design is exactly the same in both scenarios, real-time workflows rolls back the transaction, if workflow is stopped with status Canceled. This is due to the fact that real-time workflows behaves same as a post-operation plugin which if failed rolls back the complete transaction.
Since the background workflow runs outside of the main transaction, it executes each step independently and when workflow is stopped with Canceled status, complete transaction is not rolled back.
Thank you for visiting Dyn365Apps.com.
Follow me on Twitter to get the latest news, tips and tricks and more …
Until next time…