More than once I have to create a scheduled task in CRM to synchronise data from/to third party database or to run scheduled processes.
It is rather difficult to do this within CRM as it doesn’t have any concept of scheduled or recurring task. At first I thought it can be easily done by using Workflow that create record that in turn runs a plugin, but CRM soon recognize this as an infinite loop and stopped the scheduled task in it’s path.
This is caused by infinite loop prevention used by CRM platform.
Below is quoted from MSDN article.
Every time a running plug-in or Workflow issues a message request to the Web services that triggers another plug-in or Workflow to execute, the Depth property of the execution context is increased. If the depth property increments to its maximum value within the configured time limit, the platform considers this behavior an infinite loop and further plug-in or Workflow execution is aborted. The maximum depth (8) and time limit (one hour) are configurable by the Microsoft Dynamics CRM administrator.
You can change the Depth of execution using this sql:
update DeploymentProperties set IntColumn = X where ColumnName = 'MessageProcessorMaximumDepth'
MinInactiveSeconds for the time limit.
Now that we know what the problem is, we just need to avoid Depth = 8 and let the time limit counter reset at 60 minutes before the scheduling workflow re-executes. Be aware that the time limit counter restarts when depth property is incremented, so to be on the safe side, schedule the workflow at 65 minutes or so, especially if you are running async plugin.
Cheers – Sy