Like plugins, real-time workflows are executed before (pre-operation) or after (post-operation) the core operation. Both are executed inside the same database transaction.

Here are outlined some actions I have executed in order to evaluate their execution order:

  • Customization of a custom entity named Entity A which contains two text fields named ‘Plugin Text’ and ‘Workflow Text’;
  • Registration of two synchronous plugin steps for Pre Update and Post Update, which are triggered when the Entity A name field is updated:
    • Pre Update Event: sets ‘Plugin Text’ with PLUGIN | PRE UPDATE;
    • Post Update Event: sets ‘Plugin Text’ with PLUGIN | POST UPDATE;
  • Creation of two real-time workflows; one runs before the update and the other runs after the update. Both are triggered when the Entity A name field is updated:
    • Before Update: sets ‘Workflow Text’ with Workflow | PRE UPDATE;
    • After Update: sets ‘Workflow Text’ with Workflow | POST UPDATE;

Then after created and Entity A record, updated its name to ‘Test update’ and got the following audit.

default audit

The audit record shows that:

By default: real-time workflows run before than plugins for both pre and post events.

This is explained by the default value of execution order which Plugin Registration Tool sets when registering a plugin step which is equal to one.

pluginRegistrationTool

The execution order defined on Plugin Registration Tool set the Rank property of the sdkmessageprocessingstep entity that specifies the processing order within the stage.

https://msdn.microsoft.com/en-us/library/mt622430.aspx

The workflow entity stores the definition of Real-time workflows. The Rank property is not defined when they are created form the Dynamics CRM, although there is the possibility of updating it through SDK.

https://msdn.microsoft.com/en-us/library/mt622427.aspx

If the Rank is not defined then these events are executed first. If the Rank is defined then events with lower rank are executed first.

Then I updated the execution order (the Rank property) of both plugin steps to zero without updating the Rank of workflows. The audit record shows that the plugins steps run before than workflows.

audit rank 0 for plugins

Finally I set the execution order according to the next table:

Event Rank
Real-time workflow Pre Update 0
Plugin Pre Update 0
Real-time workflow Post Update 0
Plugin Post Update 1

audit final

Conclusions:

  • By default real-time workflows are executed before than plugins steps;
  • Plugin steps are executed before than real-time workflows when both have set the same rank.