As many of you know, the more items you have in a wait state in MSCRM the slower the system can perform. On of the best practices is to wake up every so often and perform your check and go back to sleep if the condition doesn’t meet.
Example:
Case: Wait 7 days and if the Status is not Completed then Send an escalation Email.
Best Practice would have workflow do some thing like this. (This is pseudo code)
Wait 1 day
If Status = Close then Stop Workflow
Wait 1 day
If Status = Close then Stop Workflow
Wait 1 day
If Status = Close then Stop Workflow
Wait 1 day
If Status = Close then Stop Workflow
Wait 1 day
If Status = Close then Stop Workflow
Wait 1 day
If Status = Close then Stop Workflow
Wait 1 day
If Status = Close then Stop Workflow
Send Escalation Email
Well, what if you wanted to change the durations from 7 days to 3. Worse yet, this is a 30 day wait process with 30 of those wonderful lines. The answer is that you can change the workflow, but all of the currently running workflows will still have the old code instantiated and they need to work through.
I came up with another method, some of you may have done the same, to make this more manageable.
I added to the case 3 fields.
- Escalation – Next Wake up
- This is a date and time for the workflow to next wake up
- Escalation – Wakeup Count
- This is an integer that tells you how many times the workflow has waited
- Escalation – Escalation On
- This is an integer that when the Escalation – Wakeup count is equal to or greater than it escalates
Putting it together in a workflow
Create a workflow for cases
Change the Scope to Organization and check off the As a Child Workflow
Add a check condition step to check the case Escalation – Next Check is blank.
Add under the if statement un update to the case Escalation – Next Check to be create on date time and set the Escalation – Wakeup Count to 1 plus the Escalation – Escalate On to 7 (1 week)
Now on a new line add the Add 1 day to the Escalation – Next Check
Add the Wait till Escalation Next Step
Now do your check to see if the condition is right to quit this workflow. In this case if the case is not active then we do not need to escalate. Stop the workflow if it is true.
Now add the escalation logic. If Escalation – Wakeup Count is => Escalation – Escalate on then send escalation and stop
Add 1 to the Escalation – Wakeup Count. Add un update to the case
It should look like this
Now add the last step and that is to call this workflow . NOTE. You will need to save the workflow before you can call it.
Publish and now try it. You will find that it is easier to update the Escalation process even on items currently running. Plus you have an easy way to force many workflows to stop within a day if needed. Enjoy and I hope this helps.
