CRM 2011 – How to Schedule Recurring Workflows in CRM 2011

Gonzalo Ruiz has recently been writing some excellent CRM blog entries and he has just written another fantastic blog entry

Scheduling recurring workflows in CRM

On Richard Knudson’s blog he said that two of his most popular blog entries ever were based on creating a scheduled workflow in CRM 4.

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.

WARNINGS:

  • 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 once

The 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.

5.  Verify

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.

14 thoughts on “CRM 2011 – How to Schedule Recurring Workflows in CRM 2011

  1. Jon Evans October 3, 2012 / 11:12 am

    I’ve been doing some work on this lately after I wanted to accomplish a task that needed a repeating workflow. I’d set the time to 10 minutes but it failed after 8 attempts. I then tried 2 hours which went beyond 8 attempts. I then wrote a few workflows to test various times out and found that a 45 minute delay failed but a 1 hour delay kept waiting (well, 1 hour 1 minute). I don’t know if different rollups change how this works (we’re on RU7) but I’m just glad that I found something that works.

    Like

    • Hosk October 3, 2012 / 11:14 am

      Hi Jon

      There is a setting which stops a workflow running more than (I think) 7 times in one hour. This is to stop recurring workflows from hogging all the processor if someone has incorrectly created a workflow.

      Like

  2. Edd Dixon February 13, 2013 / 7:44 am

    I need a workflow to fire every 5 minutes to integrate data with another system. How can I get around CRM’s infinite loop detection?

    Many thanks in advance

    Edd

    Like

    • Hosk February 13, 2013 / 9:03 am

      Every five minutes is a bit of a problem because I think CRM has a loop detection of 7 in an hour.

      The only way I can think to get around this is to create an application in C# or whatever language you want and run it as a windows service, so you are basically running it outside of CRM but connecting to CRM and doing the things you want.

      You could run a workflow once every 10 minutes or maybe have two different workflows which run every 10 minutes.

      Like

  3. DeveloperM April 1, 2013 / 7:50 pm

    This workflow contains a “custom activity”. Is this activity running against ALL account records? This is the crux, really, not the recursion, per se. I’d like to see the details of that workflow step.

    Like

  4. nellipe April 3, 2013 / 8:36 pm

    Very, Very, Very Thanks!
    You Save my Life!

    Like

  5. DarleneB July 29, 2014 / 7:34 pm

    I’m getting “cannot set unknown member”. Any idea what that means?

    Like

  6. Rem October 11, 2018 / 1:58 pm

    So what if I will start this workflow on the 31st day of the month? What will be the behavior? Will work after a month on the same day, but that month can have only 30,29 or 28 days.
    Why I am asking because I need to trigger the workflow on the last day of a month (every month). How can I do this without custom code?

    Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.