Dynamics CRM 2011 · Plugin · Workflow

CRM 2011: ExecutionContext Depth and Time Limit and Scheduled Task

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.

Read more on .

You can change the Depth of execution using this sql:
update DeploymentProperties set IntColumn = X where ColumnName = 'MessageProcessorMaximumDepth'

And MinInactiveSeconds for the time limit.

Solution
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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s