Please see the blog article Microsoft Dynamics CRM Sales Process for an introduction to sales process workflow in CRM.
In this article, I will present an approach which can be used to move the workflow from one stage to another (forward only) using a custom attribute and a series or Wait and Parallel Wait steps.
The Parallel Wait Step
The condition and parallel wait steps in the Microsoft Dynamics CRM Workflow designer may be used to implement business logic that needs to respond to various changes in the system. For example, we can create a multi-stage workflow where certain steps can be skipped based on user input. This article uses Microsoft Dynamics CRM v.4, but it is applicable for Microsoft Dynamics CRM 2011 as well.
A ‘Wait’ step in a CRM Workflow enables the workflow author to define a step that needs to wait for some user action to take place before the workflow can proceed. For example, a task that needs to be completed. The parallel wait step lets the author specify an alternate condition that would require the workflow to be canceled – for example an opportunity is ‘lost’ before all the steps in the workflow complete.
Custom field for controlling the workflow
Let’s use the salesstagecode field (displayed in the UI as “Process Code”) to create a workflow that supports skipping stages based on the value of the field. If your system uses this field for something else, you can create a custom picklist for this purpose. I have customized the field with three additional values, Stage A, Stage B and Stage C:
There are three parts in each stage of the workflow that controls which stages are processed:
1. A condition step that checks for ‘Process Code’ value before attempting any step within a stage
2. A Wait step followed by an update step that changes the ‘Process Code’ value to the next step
3. One or more Parallel Wait (Otherwise) steps that controls what happens if the opportunity record is updated by users while the workflow is waiting
Verifying the workflow
Each stage in the workflow checks for the value of the attribute before executing the steps within. At the end of the stage, an update step is used to update the stage to the next stage value.
Now let’s create two opportunity instances. The first one would set the Process Code to Stage A (or Default), second one sets the process code to Stage B.
For the second workflow to start in Stage B, we will set “Process Code” of the opportunity record to “Stage B”
For the first opportunity record, you can see that the workflow executes ‘Stage A’ steps.
Skip the current stage
Now go to the opportunity record and change Process Code to Stage B. The workflow will proceed to Stage B
Skip a stage at the beginning of the workflow
For the second opportunity record, the workflow skips past the steps in ‘Stage A’ except for condition steps and starts executing at ‘Stage B’
Ensure the workflow instance is completed if opportunity is closed
If you update the opportunity record with ProcessCode=Stage C. The workflow will skip remaining steps in Stage B and proceed to Stage C.
If you have many workflow instances in ‘Waiting’ status, it will eventually lead to performance issues. You can add a Parallel Wait step that waits for a period of time to ensure that workflows don’t wait forever.
If you have completed workflow instances that are no longer needed, you may want to delete them using the CRM application or using Bulk Delete.
In Microsoft Dynamics CRM 2011 you can mark a workflow definition so that workflow instances will be deleted once the workflow completes. To access this flag, click on the ‘Administration’ tab. The checkbox is at the bottom of the dialog titled “Automatically delete completed workflow jobs (to save disk space)”.