Gonzalo Ruiz has recently been writing some excellent CRM blog entries and he has just written another fantastic blog entry
So it was with interest when I saw the current blog entry on this subject and because there isn’t any scheduling tool within CRM but this is functionality that a lot of people would find useful. This makes articles about scheduling interesting and useful to a lot of people working with CRM 2011.
Although below the instructions taken from the excellent blog post, he does attach some warnings and this is true because you have to be very careful about clogging up the ASYNC service because if you have ever experienced it going down you will know how important it is to CRM, if it shuts down or even slows down it’s a big problem.
- Every time you create a recurring workflow, you should carefully consider what resource consumption implications it will have. Recurring operations tend to utilize a large amount of resources which can cause lagging to the CRM Asynchronous processing service.
- You must select a primary entity for your workflow which will never be deleted, otherwise the entire recurring workflow will be cancelled. For example, you can set the primary entity of your workflow to be systemuser and trigger it the first time regarding your own system user.
- There is a loop detection mechanism in CRM 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. Therefore, the workflow above should work fine because it has 1 month of inactivity so each time it executes the depth will be reset and it will never be cancelled by the loop detection mechanism.
1. Define triggers:
Define the workflow as On-Demand and Child workflow (not automatic triggers)2. Define process:
Define the body of the workflow to represent the set of actions that must occur every month:
3. Add the Wait:Now you need a way to tell the workflow engine to repeat the process every month. To do so, I will first insert a wait step that will tell the workflow engine to wait for 1 month:
After the step, I need a way to “restart” the workflow. Since there are no while/for loops in the workflow designer, we must find another solution. I will simply create a recurrence pattern by having an “Execute child workflow” step which executes itself. Because the workflow is defined as a child workflow, it will call itself every month. After I activate the workflow it looks like this:
4. Trigger the workflow onceThe first time that the workflow executes, it must be triggered manually, after that it will schedule itself monthly from the time that it was executed manually. Since it is defined as an on-demand workflow, you can simply navigate to your primary entity and trigger the workflow manually.
Once your workflow has been triggered for the first time, it should appear in the system jobs grid, waiting for the next month to resume execution:Note that “month” is not the same as 30 days, it actually uses the calendar month definition, since CRM workflow uses the .NET DateTime class. Therefore, if it was first triggered the 1st of the month, it will always trigger the 1st of the month regardless of the number of days in a month.