Microsoft Dynamics 365 workflows are an amazing tool. They allow for simple, or complex automation of tasks within Dynamics 365 that can make an incredible difference to an organization. Workflows provide further utility in that they often act as an alternative to building a custom plug-in.
- Elements of a workflow
- Workflow components
- Workflows in action
- Multi-staged workflows
- Infinite loops
- Checking workflow status
Dynamics 365 workflows consist of a series of steps and rules that serve to automate a business process. A workflow can run on an out-of-box entity or a custom entity. Workflows can be initiated manually, or they can be initiated automatically, in a number of different ways.
When you create a new workflow you have the option to check Run this workflow in the background. Leaving the box unchecked means you will create a real-time (synchronous) workflow. Checking this box means you are creating a background (asynchronous) workflow and it will allow for wait conditions. Your configuration options will change based upon what you select here. You can always change this later in the actions menu by choosing Convert to real-time workflow or Convert to background workflow.
In the above image, you can see the options available when creating a background workflow.
You can also see the Scope, when expanded, has the following options:
User– when this option is selected, the Workflow will exclusively run on records with the same owner as the Workflow.
Business Unit- when this option is selected, the Workflow will exclusively run on records owned by any user in the same Business Unit as the owner of the Workflow.
Parent: Child Business Units- when this option is selected, the Workflow will exclusively run on records owned by any user in the same Business Unit—or
Organization- when this option is selected, the Workflow will run on records owned by any user.
Start when: Record is created- workflow will begin when a record is created within the selected entity.
Start when: Record status changes- workflow will begin when a record status is changed within the selected entity.
Start when: Record is assigned- workflow will begin when a record is assigned to someone within the selected entity.
Start when: Record is deleted- workflow will begin when a record is deleted within the selected entity.
Start when: Record fields change- workflow will begin when a record field changes within the selected entity. SEE BELOW FOR EXAMPLE.
This is the page that is displayed upon selecting the Start When: Record Fields Change. Here you will select a field, which is related to the Entity that the workflow will run on. When this option is chosen, the workflow will start based on any change made to said field.
A workflow in Microsoft Dynamics 365 consists of a series of steps and rules to achieve a goal. The following are the available steps in a workflow:
Stage: a stage is used to split a workflow into manageable sections.
Check Condition: a check condition is made up by an if statement, and a then statement.
Conditional Branch: can only be created directly after a Check Condition. Functions as an Otherwise, If, Then statement.
Default Action: used to run a series of steps if the Check Condition and Conditional Branch fail.
Wait: waits until a condition is met, then performs desired step.
Parallel Wait Branch: a wait condition that runs parallel to the original workflow.
Create Record: creates an entity record (or a related entity record) in selected entity.
Update Record: updates selected entity record (or related entity record) field with desired value, or with a dynamic value.
Assign Record: assigns selected entity record (or a related entity record) to a user or a team.
Send E-mail: sends an e-mail via new e-mail creation or via e-mail template.
Start Child Workflow: starts a Child Workflow. Usually to perform a task outside the original selected entity.
Change Status: changes status field of selected entity record.
Stop Workflow: stops the workflow with a status of cancelled or completed.
Here’s an example business problem: Alpha Company gets about 20 new Accounts a month. They’d like for their Sales Manager, Sean, to automatically be assigned the Accounts, so he can divvy them up fairly (or unfairly!).
Here is an example of a workflow to accomplish this task:
When an Account entity record is created, the Account is assigned to a User. Once it is assigned to a User, an e-mail will automatically be sent to the User notifying them towards their new ownership of the Account. The e-mail will contain a record URL that links directly to the Account being assigned to the User.
- Workflow will activate as a Process.
- Workflow Scope is set to Organization. Workflow is set to run whenever a record is created in the Account entity.
- Assign account to a specific User.
- Send E-mail with URL link to Account, via new e-mail creation (see image below)
- Stop Workflow with a status of Succeeded.
A. Click Insert Hyperlink. In the Text to display field, choose Look for Account > Account Name. In the URL field, choose Look for: Account > Record URL (Dynamic). This will build a hyperlink that when clicked brings you to the assigned account.
B. Click the From field on the form, then on the right-hand form assistant panel, select Look for: Account > Created By. This will send the email from the creator of the account.
C. Click the To field, then on the right-hand form assistant panel, select Look for: Account > Owning User. This will send the e-mail to the user assigned to the account.
D. Click the Subject field on the form, then on the right-hand form assistant, select Look for: Account > Account Name. This will insert the account name into the subject line of the email.
That wraps up an example of solving a basic business problem with a simple workflow.
As workflows become more and more complex, they grow in length and size. Due to this growth, organizing them properly becomes very important. Here are some things to keep in mind.
Stages are a great way to organize workflows, as they break down a number of tasks into smaller sections, and allow for task grouping. The workflow only runs through one stage at time. This helps reduce the performance stress and lethargy created by large, verbose workflows.
A poorly designed workflow can result in an infinite loop where the workflow runs indefinitely, using up available system resources like memory and disk space. For example, consider a workflow that creates an account that is registered to run when an account is created. When a user creates an account, the workflow runs and creates another account that causes the workflow to run again, and so on. This results in an Infinite Loop.
Microsoft Dynamics 365 has run-time logic to find and stop workflows that have entered an infinite loop. The system automatically stops the workflow
There is a loop detection mechanism in CRM for Dynamics 365 which would cancel processes/plugins that create infinite loops as the one above. The maximum depth for a recurrence/loop is 8; however, the depth is reset after 10 minutes of inactivity
Review workflow logic carefully. Workflows that include infinite loopbacks, which, because of semantic or logic errors, can never terminate through normal means, can greatly affect overall workflow performance. When creating and implementing workflow functionality within a deployment, be sure to review the logic in workflow rules to ensure there are no loopback issues.
Microsoft Dynamics 365 allows us to monitor running workflows in a couple of areas in the system. This allows us to check the progress of running workflows for errors or logic that may have not been considered when designing the workflow.
From within the workflow in the Process Sessions area we can see the records impacted by the workflow
Or under Settings in the System Jobs area we can see all workflow statuses