Skip to main content



No record found.

Microsoft Dynamics CRM forum

CRM Context.Depth issue

Posted on by 690

 have this scenario which is causing the Depth issue in CRM

I have a Entity (EntityA) which has 3 Boolen flags (A1, A2, A3). There are 3 workflows mapped to the entity (WorkflowA1,WorkflowA2,WorkflowA3)

I have another Entity (EntityB) which has one Boolean Flag (B1). There is 1 workflow attached to this entity (WorkflowB1)

The data is in this mapping. For a record in EntityA there will be multiple records in EntityB (Parent - Child data).

Here is the flow. On Setting of the Flag A1, the WorkflowA1 starts. This workflow (WorkflowA1) just gets the corresponding records in EntityB for the current record of EntityA. After retreving it sets all the B1 flag to True. This gets the WorkflowB1 started on records of EntityB. On completition of WorkflowB1 it would set the flag B1 back to false. In the mean time the WorkflowA1 would monitor the flags to be changed back to false. One all flags are of corresponding records of entityB are false, this concludes the WorkFlowA1. On Completion of WorkFlowA1 it sets the flag A2 to true.

The flag A2 = true kicks up WorkflowA2. After this completes, it sets the flag A3 to true. The flag A3 = true kicks up WorkflowA3. After this completes it indicates the completion of the whole process. The Workflow3 does the heavy work and during this process lot of plugins on other entities fire.

I had a issue where i got the error "Pluginfailed" . On further looking at trace I found out it was complaining about depth.

So I put in some logging. Here is what I found out :

WorkflowA1 : Depth is 1 WorkflowB1 : Depth is 2 WorkflowA2 : Depth is 3 WorkflowA3 : Depth is 3

I am not sure why it is treating the WorkflowA2 as depth 3. I can understand WorkflowB1 running at depth 2.

Because of this and some plugins, my process fails.

I do not have an option to look at the plugin implementation. Is there anything I can do so that at least WorkflowA1,WorkflowA2,WorkflowA3 run at depth 1 only.

Any pointers will help. Please let me know if any additional information is required.

Thanks, Girija Shankar

  • Verified answer
    RE: CRM Context.Depth issue

    Hi Scott,

    We merged Workflow 1 and Workflow 2 into one workflow. We tried increasing the Context Depth to 9 and it worked so we figured out it was one depth that we need to get rid off. So by merging the workflows we ended up at 8 which eventually works. Sad there is no other way :(

    - Girija

  • ScottDurow Profile Picture
    ScottDurow 50,166 on at
    RE: CRM Context.Depth issue

    How did you get on? Did you figure it out?

  • Suggested answer
    ScottDurow Profile Picture
    ScottDurow 50,166 on at
    RE: CRM Context.Depth issue


    The depth is not a product of the number of entities deep - it is a product of the number of nested pipeline events. This means that everytime a 'child' event invokes a pluging/workflow the context is invoked.

    So if WorkflowA2 is triggered by Workflow A1 then the depth will increment - then if WorkflowA2 triggers WorkflowB1 then the depth increments. Then if WorkflowB1 triggers WorkflowA3 then again the depth will increase again.

    Hope this helps

  • RE: CRM Context.Depth issue

    Hi Scott,

    Thanks for the response.

    In my case the WorkflowA1 sets the flag A2 which invokes the WorkflowA2 . They (The flag fields and the workflows) are all on the same entity (EntityA ) but still the depth increases to 3 when the WorkflowA3 starts.

    It is not like the WorkflowB1 (which is on EntityB) which sets the flag A2. If that would have been the case it was understandable that the calling pattern determining the depth, but here the a workflow on the same entith actullay kicks off another.

    I did a small test without the EntityB (and its workflow invoked) and I invoked all the flags the same way , WorkFlowA1 setting flag A2 and WorkflowA2 setting flag A3. In this case the depth is 1 across the workflow A1,A2, A3.

    When you say the depth being reset is by top level update action, what do you refer to. Can you point me a example considering my scenario ?

    - girija

  • Suggested answer
    ScottDurow Profile Picture
    ScottDurow 50,166 on at
    RE: CRM Context.Depth issue


    I think perhaps the issue here is the definition of 'depth' - the depth get's incremented everytime there is a follow on event executed and so even though you are essentially returning to the context of Entity A - the execution of workflow A2 is still triggered by a previous workflow and so there is a previous depth that is incremented.

    The only way that Workflow A2 would get the depth reset is if it was triggered by a top level update action rather than via another workflow/plugin.

    Hope this helps!

  • RE: CRM Context.Depth issue

    Hi John,

    Thanks for the response.

    It is not an indefinite loop because if I increase the depth to 9 it works without any error.

    My responses :

    1. The CRM is 2016 on Premises

    2. Workflows are all asynchronous

    3. The exact error is  "“This workflow job was canceled because the workflow that started it included an infinite loop”

    4. The workflows are simple. They are custom. They are configured to invoke on Field change. They are not on demand workflows. The scope is organization. And in the steps they only check on condition (i.e. :  If the field related is "Yes" then execute..)

    My question is on the behavior. My observation says that if I have multiple workflows on the same table and one sets a field that kicks of the other the depth remains 1 all through, But if one workflow invokes some other workflows in another entity and waits (as my case WorkFlowA1) then the depth increases to 2, and event when ot comes back to the original entity it again increases the depth to 3. My Initial workflow never completes but waits, so why depth increases ?

    - Girija

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM Context.Depth issue

    Hi Girija,

         My understanding is that if you're getting an error complaining about depth in the workflow, it's probably due to an infinite loop in your logic. Having said that, please answer a few questions:

     - What version of CRM are you using?

     - Are your workflows asynchronous or real-time?

     - Can you provide the exact error you are getting?

     - What do your workflows looks like? Can you provide screenshots of their steps?

    Without having more of the above information it will be difficult to know what the problem is. Please provide.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .


André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,995 Super User

Martin Dráb Profile Picture

Martin Dráb 225,610 Super User

nmaenpaa Profile Picture

nmaenpaa 101,148


Featured topics

Product updates

Dynamics 365 release plans