Note: Workflows in Dynamics CRM should not be confused with “Business Rules” and “Business Process Flows”. For more information on both of those topics, see my earlier posts on Business Rules and Business Process Flows.
Note: CRM 2013 is not due to be released until October 2013. The information provided in this blog might different from the final product.
Some key points about real-time workflows:
- Real-time workflow runs in the same transaction at the same time as the event that triggered off the workflow in the first place. That is, if a workflow is set to fire on the creation of an account record, the workflow process will now be handled by the w3wp worker process. If for some reason the real-time workflow is “cancelled” (e.g. user cancelling the workflow or the workflow has a step which sets its own status to “Cancelled”), the whole transaction will be rolled back, including the event that triggers the workflow in the first place, to prevent the entire operation.
- You can choose to run real-time workflows either as the CRM user who owns the workflow or as the CRM user whose action triggered the workflow. This is set as “Execute As”. It is a useful option for synchronous workflows as there might be operations within the workflow which should be completed by the calling user for audit tracking (e.g. audit tracking should show that the calling user has updated a field that is processed by a real-time workflow). For asynchronous workflows however, they can only be run by the owner of the workflow and not by the calling user in CRM.
- Real-time workflow offers you the option of starting the process either BEFORE or AFTER the event that triggers the workflow. This mirrors the pre-operation (stage 20) and post-operation (stage 40) pipelines that are available to plugins.
Time to go build some real-time workflows! Let’s start with the following simple requirements:
1) On the creation of an account record, if an end-user completes the “Phone” field, we would like to change the “Contact Method” dropdown on the account form to specify “Phone” option as the “Contact Method.
2) If the “Phone” field is updated afterwards, we want the “Contact Method” and “Phone” preference be set according to the following table
|Contact Method||Phone Preference|
|Phone Has Data||Phone||Allow|
|Phone Has No Data||Do Not Allow|
3) All changes related to “Contact Methods” for an account must be displayed to the user immediately after account creation or update of “Phone” field.
Building A Custom Real-Time Workflow
Here is what the workflow builder looks like in CRM 2013: important step here is to leave the “Run this workflow in the background (recommended)” if you are building a real-time workflow.
Here is how I set up my real-time workflow to meet the above requirements.
Key points to note are:
- I would like the workflow to run “after” account creation and also “after” field changes so I left the “As an on-demand process” and “as a child process” unchecked in the workflow builder. The “record fields changed” option I have set to trigger on “Phone”.
- I have set this workflow to execute as “the user who made changes to the record”, as I would like the end-user who creates the account or changes the phone field to also be the logged on the audit as the end-user who sets the “Contact Method” and “Phone” preference.
- The workflow steps are very simple. It checks if the account record’s phone field contains data or not. If yes, update the account’s “Contact Method” and “Phone” preference
- If not, update the account’s “Contact Method” and “Phone” preference accordingly
Now all that is needed is to save and activate this workflow. To check this this workflow is functioning correctly, let’s create a new account in CRM using the “quick create” form and set the “Main Phone” number.
Looking at the newly created account record, the workflow has set the “Contact Preferences” to correct values.
Removing the Phone field on this account record will trigger the workflow again and sets the “Contact Preferences” accordingly.
That’s it! No code involved! Very simple!