featured-973-1769645069.jpg

How to Create Workflows in Dynamics 365: A Practical Guide to Automated Processes

Workflows in Dynamics 365 are the engine of automation, allowing you to streamline business processes, improve efficiency, and ensure consistency. This article provides a detailed, practical guide to creating workflows in Dynamics 365, focusing on real-world scenarios and actionable steps. We will cover designing, configuring, and deploying workflows to automate critical business functions.

This guide will explore specific workflow types and their configuration options, enabling you to implement custom solutions tailored to your specific business needs. By the end of this guide, you will be equipped with the knowledge to create and manage workflows effectively in Dynamics 365.

Understanding Dynamics 365 Workflows: Types and Triggers

Dynamics 365 offers two primary types of workflows: real-time workflows and background workflows. Understanding the differences between these types is crucial for selecting the appropriate workflow for your automation needs. Real-time workflows execute synchronously, meaning they occur immediately as a user interacts with the system. Background workflows, on the other hand, execute asynchronously, allowing the system to process tasks without immediately impacting the user experience.

Real-time Workflows: Ideal for scenarios where immediate action is required, such as enforcing data validation rules or sending immediate notifications. These workflows can be triggered by events like record creation, update, or deletion. However, because they run synchronously, poorly designed real-time workflows can negatively impact system performance.

Background Workflows: Best suited for long-running processes, such as sending weekly reports or performing complex calculations. These workflows are queued and processed by the system, minimizing disruption to the user. They are typically triggered by the same events as real-time workflows but can also be scheduled to run at specific times.

Workflow Triggers

Workflows in Dynamics 365 are initiated by specific triggers, which can be either events within the system or scheduled occurrences. Common triggers include:

  • Record Creation: The workflow starts when a new record is created in a specific entity.
  • Record Update: The workflow starts when a field within a record is updated. You can configure workflows to trigger only when specific fields are modified.
  • Record Deletion: The workflow starts when a record is deleted.
  • Record Status Change: The workflow starts when the status of a record changes.
  • Manual Trigger: Users can manually start the workflow from the record form.
  • Scheduled Trigger: The workflow runs at a predefined schedule.
  • Child Workflow Completion: A workflow can be triggered upon the completion of another (parent) workflow.

Selecting the appropriate trigger is critical for ensuring that your workflow executes at the right time and under the correct conditions.

Example 1: Real-Time Workflow for Data Validation

Let’s create a real-time workflow that validates the “Email Address” field on the “Account” entity. If the email address is not in a valid format, the workflow will display an error message and prevent the record from being saved.

  • Step 1: Navigate to Settings > Processes in Dynamics 365.
  • Step 2: Click New.
  • Step 3: Enter a name for the workflow (e.g., “Account Email Validation”).
  • Step 4: Select “Account” as the Entity.
  • Step 5: Select “Workflow” as the Category.
  • Step 6: Ensure that “New blank process” is selected.
  • Step 7: Check the “Real-time workflow” option.
  • Step 8: Under “Start when,” select “Record is created” and “Record is updated.”
  • Step 9: Click “Add Step” and select “Check Condition.”
  • Step 10: Define the condition to check if the Email Address field contains “@” and “.” characters.
  • Step 11: Within the “If condition is false” branch, click “Add Step” and select “Stop Workflow.”
  • Step 12: In the “Set Properties” window for the “Stop Workflow” step, select “Canceled” as the status and enter an error message in the description (e.g., “Invalid email address format”).
  • Step 13: Activate the workflow.

Now, when a user creates or updates an account record with an invalid email address, the workflow will prevent the record from being saved and display the error message.

Example 2: Background Workflow for Sending Weekly Reports

Let’s create a background workflow that sends a weekly report of all new leads created in Dynamics 365. This workflow will run every Monday morning.

  • Step 1: Navigate to Settings > Processes in Dynamics 365.
  • Step 2: Click New.
  • Step 3: Enter a name for the workflow (e.g., “Weekly New Leads Report”).
  • Step 4: Select “Lead” as the Entity.
  • Step 5: Select “Workflow” as the Category.
  • Step 6: Ensure that “New blank process” is selected.
  • Step 7: Uncheck the “Real-time workflow” option (this makes it a background workflow).
  • Step 8: Under “Start when,” select “Record is created.”
  • Step 9: Enable “Run this workflow in the background.”
  • Step 10: Click “Add Step” and select “Send Email.”
  • Step 11: In the “Set Properties” window for the “Send Email” step, configure the email details, including the recipient, subject, and body. You can use dynamic values (e.g., the lead’s name) in the email.
  • Step 12: Add a “Create Record” step to create an Activity entity record tracking the email send.
  • Step 13: Click “Add Step” and select “Wait Condition.” Set the wait condition to wait until the next Monday at 8:00 AM.
  • Step 14: After the wait condition, loop back to the “Send Email” step. To do this, add an “Update Record” step that updates a “Loop Counter” field (create a new custom field on the Lead entity) and then add a “Check Condition” step that checks if the loop counter is less than the maximum number of loops (e.g., 52 for weekly reports for a year). If the counter is less than the maximum, go back to sending the email; otherwise, stop the workflow. If you only want the workflow to run indefinitely, you do not need these steps.
  • Step 15: Activate the workflow.

This workflow will now send a weekly report of new leads every Monday morning. Note the complexity of looping workflows, often best avoided by scheduling jobs directly in the operating system instead.

Expert Tip: When designing workflows, start with a clear understanding of the business process you want to automate. Map out the steps involved and identify the triggers that will initiate the workflow. Consider the potential impact on system performance and choose the appropriate workflow type (real-time or background) accordingly. If you are concerned about synchronous workflow performance consider asynchronous workflows. Also consider Power Automate, as Microsoft has moved many workflow capabilities there.

Designing Effective Workflow Logic: Conditions, Actions, and Branching

The core of any workflow lies in its logic, which determines how the workflow behaves based on specific conditions. Dynamics 365 provides a rich set of tools for designing workflow logic, including conditions, actions, and branching.

Conditions

Conditions allow you to define criteria that must be met for a particular branch of the workflow to execute. You can use conditions to check the values of fields, the status of records, or other relevant factors. Conditions can be combined using logical operators (AND, OR) to create complex expressions.

For example, you might use a condition to check if the “Budget Amount” field on an opportunity record is greater than $10,000. If the condition is true, the workflow could automatically assign the opportunity to a senior sales representative.

Actions

Actions are the tasks that the workflow performs when a specific condition is met. Dynamics 365 provides a wide range of actions, including:

  • Create Record: Creates a new record in a specified entity.
  • Update Record: Updates an existing record.
  • Assign Record: Assigns a record to a user or team.
  • Send Email: Sends an email message.
  • Start Child Workflow: Starts another workflow.
  • Change Status: Changes the status of a record.
  • Perform Action: Executes a custom action (requires custom code).
  • Stop Workflow: Stops the workflow with a specified status (Succeeded, Canceled, Waiting).

You can combine multiple actions within a single workflow to perform complex tasks. For example, you might create a workflow that automatically creates a task for a sales representative when a new lead is created, sends an email to the lead, and updates the lead’s status to “Contacted.”

Branching

Branching allows you to create multiple paths within a workflow, based on different conditions. You can use branching to handle different scenarios or to perform different actions based on the values of specific fields.

For example, you might use branching to create a workflow that handles high-priority and low-priority cases differently. If the case priority is “High,” the workflow could automatically assign the case to a senior support representative and send an immediate notification. If the case priority is “Low,” the workflow could assign the case to a junior support representative and add it to a queue.

Example 1: Workflow for Opportunity Assignment based on Budget

Let’s create a workflow that automatically assigns opportunities to different sales representatives based on the “Budget Amount.” Opportunities with a budget greater than $50,000 will be assigned to a senior sales representative, while opportunities with a budget less than $50,000 will be assigned to a junior sales representative.

  • Step 1: Navigate to Settings > Processes in Dynamics 365.
  • Step 2: Click New.
  • Step 3: Enter a name for the workflow (e.g., “Opportunity Assignment by Budget”).
  • Step 4: Select “Opportunity” as the Entity.
  • Step 5: Select “Workflow” as the Category.
  • Step 6: Ensure that “New blank process” is selected.
  • Step 7: Select “Real-time workflow” or “Background workflow” based on your requirements.
  • Step 8: Under “Start when,” select “Record is created.”
  • Step 9: Click “Add Step” and select “Check Condition.”
  • Step 10: Define the condition to check if the “Budget Amount” is greater than $50,000.
  • Step 11: Within the “If condition is true” branch, click “Add Step” and select “Assign Record.” Assign the opportunity to the senior sales representative.
  • Step 12: Within the “If condition is false” branch, click “Add Step” and select “Assign Record.” Assign the opportunity to the junior sales representative.
  • Step 13: Activate the workflow.
Example 2: Workflow for Case Escalation based on Priority

Let’s create a workflow that automatically escalates high-priority cases to a support manager after 24 hours if they are not resolved.

  • Step 1: Navigate to Settings > Processes in Dynamics 365.
  • Step 2: Click New.
  • Step 3: Enter a name for the workflow (e.g., “Case Escalation by Priority”).
  • Step 4: Select “Case” as the Entity.
  • Step 5: Select “Workflow” as the Category.
  • Step 6: Ensure that “New blank process” is selected.
  • Step 7: Select “Background workflow.”
  • Step 8: Under “Start when,” select “Record is created” and “Record is updated.”
  • Step 9: Click “Add Step” and select “Check Condition.”
  • Step 10: Define the condition to check if the “Priority” is “High.”
  • Step 11: Within the “If condition is true” branch, click “Add Step” and select “Wait Condition.” Set the wait condition to wait for 24 hours.
  • Step 12: After the wait condition, click “Add Step” and select “Check Condition.” Check if the “Status Reason” is still “Problem Solved”.
  • Step 13: If the case is not resolved after 24 hours, add an “Update Record” step to escalate the case to the support manager by updating a custom “Escalated To” field with the manager’s user lookup.
  • Step 14: Add a “Send Email” step to notify the support manager about the escalated case.
  • Step 15: Activate the workflow.

Expert Quote: “Workflow design is an iterative process. Start with a simple workflow and gradually add complexity as needed. Test your workflows thoroughly to ensure they behave as expected. Don’t be afraid to refactor workflows as your business processes evolve.” – Dynamics 365 Workflow Expert

Advanced Workflow Techniques: Custom Actions and Code Activities

While the standard actions provided by Dynamics 365 are sufficient for many workflow scenarios, there are times when you need to perform more complex tasks that require custom code. Custom actions and code activities allow you to extend the capabilities of workflows and integrate with external systems.

Custom Actions

Custom actions are reusable components that encapsulate custom logic. They can be called from workflows, dialogs, or other custom code. Custom actions can perform a wide range of tasks, such as calculating complex values, integrating with external web services, or performing data transformations.

To create a custom action, you need to define its input parameters, output parameters, and the logic that it will execute. The logic can be implemented using custom code (C#) or using the built-in workflow designer.

Code Activities

Code activities are custom components written in C# that can be executed within a workflow. They provide a way to perform complex tasks that cannot be accomplished using the standard workflow actions. Code activities can be used to interact with the Dynamics 365 database, call external web services, or perform any other custom logic.

To create a code activity, you need to create a class that implements the IWorkflowActivity interface. This interface defines a single method, Execute, which contains the logic that the activity will perform. You also need to register the code activity with Dynamics 365 so that it can be used in workflows.

Example 1: Custom Action for Calculating Credit Risk Score

Let’s create a custom action that calculates the credit risk score of an account based on various factors, such as annual revenue, number of employees, and credit history. The custom action will take these factors as input parameters and return the credit risk score as an output parameter.

  • Step 1: Create a new class library project in Visual Studio.
  • Step 2: Add references to the Dynamics 365 SDK assemblies (Microsoft.Xrm.Sdk.dll, Microsoft.Crm.Sdk.Proxy.dll).
  • Step 3: Create a class that inherits from CodeActivity.
  • Step 4: Define input and output parameters for the custom action using the [Input("Parameter Name")] and [Output("Parameter Name")] attributes.
  • Step 5: Implement the Execute method to calculate the credit risk score based on the input parameters. This will involve writing the formula for your credit risk scoring.
  • Step 6: Build the project to generate a DLL file.
  • Step 7: Register the custom action with Dynamics 365 using the Plugin Registration Tool.
  • Step 8: In Dynamics 365, create a new workflow and add a “Perform Action” step.
  • Step 9: Select the custom action you created in the previous steps.
  • Step 10: Configure the input parameters of the custom action by mapping them to fields on the account record.
  • Step 11: Configure the output parameter of the custom action by mapping it to a new field on the account record (e.g., “Credit Risk Score”).
  • Step 12: Activate the workflow.

Now, when a new account is created or updated, the workflow will automatically calculate the credit risk score and store it in the “Credit Risk Score” field.

Example 2: Code Activity for Integrating with an External Web Service

Let’s create a code activity that integrates with an external web service to retrieve customer information based on their account number. The code activity will take the account number as an input parameter and return the customer information (e.g., name, address, phone number) as output parameters.

  • Step 1: Create a new class library project in Visual Studio.
  • Step 2: Add references to the Dynamics 365 SDK assemblies (Microsoft.Xrm.Sdk.dll, Microsoft.Crm.Sdk.Proxy.dll).
  • Step 3: Create a class that implements the IWorkflowActivity interface.
  • Step 4: Define input and output parameters for the code activity using the [Input("Parameter Name")] and [Output("Parameter Name")] attributes.
  • Step 5: Implement the Execute method to call the external web service and retrieve the customer information. This will require using the `HttpClient` class to make an HTTP request to the service. You’ll need to serialize the request and deserialize the response using JSON or XML libraries.
  • Step 6: Build the project to generate a DLL file.
  • Step 7: Register the code activity with Dynamics 365 using the Plugin Registration Tool.
  • Step 8: In Dynamics 365, create a new workflow and add a “Perform Action” step.
  • Step 9: Select the code activity you created in the previous steps.
  • Step 10: Configure the input parameter of the code activity by mapping it to the “Account Number” field on the account record.
  • Step 11: Configure the output parameters of the code activity by mapping them to new fields on the account record (e.g., “Customer Name,” “Customer Address,” “Customer Phone”).
  • Step 12: Activate the workflow.

Now, when a new account is created or updated, the workflow will automatically retrieve the customer information from the external web service and store it in the corresponding fields on the account record.

External Link: For more information on custom actions and code activities, refer to the official Dynamics 365 documentation: Microsoft Dynamics 365 Custom Actions

Workflow Management Best Practices: Testing, Deployment, and Monitoring

Creating workflows is only the first step. To ensure that your workflows are effective and reliable, you need to follow best practices for testing, deployment, and monitoring.

Testing

Thorough testing is crucial for identifying and resolving issues before deploying workflows to a production environment. It is important to test workflows with a variety of data scenarios to ensure they handle all possible cases correctly.

Here are some testing best practices:

  • Unit Testing: Test individual components of the workflow, such as conditions and actions, to ensure they function as expected.
  • Integration Testing: Test the entire workflow to ensure that all components work together correctly.
  • User Acceptance Testing (UAT): Involve end-users in the testing process to ensure that the workflow meets their needs and expectations.
  • Performance Testing: Test the workflow under load to ensure that it does not negatively impact system performance.
Deployment

Deploying workflows involves moving them from a development environment to a production environment. It is important to follow a structured deployment process to minimize the risk of errors or disruptions.

Here are some deployment best practices:

  • Use a Solution: Package your workflows and related components (e.g., custom entities, fields) into a solution for easy deployment and management.
  • Import the Solution: Import the solution into the target environment (e.g., production).
  • Test in Staging: Deploy the solution to a staging environment that mirrors the production environment to perform final testing before deploying to production.
  • Activate Workflows: After importing the solution, activate the workflows to enable them.
  • Document the Deployment: Document the deployment process, including any configuration changes that were made.
Monitoring

Monitoring workflows is essential for identifying and resolving issues that may arise after deployment. It is important to track workflow performance and error rates to ensure they are functioning correctly.

Here are some monitoring best practices:

  • Workflow Logs: Regularly check the workflow logs for errors or warnings. The logs provide detailed information about workflow execution, including the steps that were executed and any errors that occurred. These can be found in the System Jobs area.
  • System Jobs: Monitor the status of system jobs to identify workflows that are failing or taking too long to execute.
  • Performance Monitoring: Use performance monitoring tools to track the performance of workflows and identify any bottlenecks.
  • User Feedback: Collect feedback from users to identify any issues or areas for improvement.
Example: Monitoring Workflow Errors using System Jobs

To monitor workflow errors, navigate to Settings > System Jobs in Dynamics 365. Filter the system jobs by “Workflow” and “Status Reason = Failed.” This will display a list of all workflows that have failed. You can open each system job to view the error details and identify the cause of the failure.

The error details typically include the workflow name, the step that failed, and the error message. You can use this information to troubleshoot the issue and resolve the failure.

Workflow StageActionDescription
DevelopmentTestingThoroughly test workflows with various data scenarios.
DeploymentSolution PackagingPackage workflows into solutions for easy deployment.
ProductionMonitoringRegularly monitor workflow logs and system jobs for errors.

Expert Tip: Implement a robust error handling strategy in your workflows. Use the “Try-Catch” pattern to gracefully handle exceptions and prevent workflows from failing. Log errors to a custom entity or external system for further analysis.

person

Article Monster

Email marketing expert sharing insights about cold outreach, deliverability, and sales growth strategies.