Skip to main content

Notifications

Announcements

No record found.

[KB] Dynamics 365 Workflow Step – Stop Workflow – Succeeded vs Canceled (Cancelled)

Dynamics 365 Workflow Step - Stop Workflow - Succeeded vs Canceled

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;

  1. Succeeded
  2. Canceled (Cancelled)

In this article, I would investigate how Dynamics 365 (CRM) behaves when selecting each option.

Real-time Workflow

Let’s create a real-time workflow.

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.

Result

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.

Business Process Error - Stop Workflow - Canceled

Background Workflow

Let’s convert the workflow to a background workflow.

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

Background Workflow - Succeeded

Scenario – Canceled

Background Workflow - Canceled

Result

As you can see below, two Test records were created successfully (Notice the time).

Background Workflow - Result

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.

Real-time Workflow

Trigger Real-time Workflow on Create

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.

Background Workflow

Background Workflow - Trigger on Create

Create two records with Outcome field set to Success in one and Failure in the other.  In both scenarios, records get created.

Trigger Background on Create

Conclusion

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…

Comments

*This post is locked for comments