Dynamics CRM 4.0 Workflows calling itself (Recursive)

Simon Phillips, 17 August 2010

Just the other day while helping a colleague, I discovered something very cool you can do with workflows that I didn’t know was possible. A child workflow can call itself (Can set the workflow to start again) and place itself into a loop - an infinite loop if you are not careful. Knowing this you can create some very helpful and useful workflows to do a range of different things, for example, set Reminders.

If you are going to do this, the first point to note is you must add a condition to stop the workflow for some reason or another or the workflow will cause a huge drain on your system. In the example I will use to explain how this will work I am going to be sending a reminder about overdue invoices. So, of course there is the usual process - make sure you create the workflow for invoices and give it an appropriate name.

Now, there are a few of the basic workflow settings that need to be set correctly for this to work. This workflow needs to be set as a ‘child workflow’ and when to start which for me is on record creation.

Here are the steps of the workflow:

1. It then needs to check if the invoice is still to be paid

    a. Stop the workflow if it has been paid

2. If not, send reminder email about it(or create task, or phone call)

3. Start workflow again (for those of you who make the same mistake as me and can’t find the workflow, you have to save it first before it will appear on the list)

Below is what this looks like:

However, this is still incorrect as it will develop into that infinite loop I told you about and you will get email spammed if you do not change this. So there is one more minor change to make sure that this doesn’t happen. Simply place a timeout step in there for one day so that you get reminded every day about overdue invoices.

Below is what it should look like:

I hope this post is helpful to you.