web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Context depth increasing 3 at the time of account qualify/Create

(0) ShareShare
ReportReport
Posted on by 737

Hi Experts,

I am getting a issue in account creation plugin execution, at the time of qualifying a lead to account, there is account creating but the context depth value is 3 and hence my plugin is not executing because I have condition where only depth is less than equal to 2 than my plugin code will execute. As per my understanding context depth is checked in plugin to avoid infinite loops of execution.

My plugin is executing synchronously at the time of record creation and updation 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi B . K ,

    As per my understanding plugin depth we need to check when plugin logic also triggering  same events/message(Create/Update etc ) for same entity inside plugin  under which message(events) plugin step has been registered. So its not mandatory to check plugin depth if you are not doing the same operation inside plugin.

    Let say you are updating one account and in the update message of account entity there have a plugin and inside plugin you are doing another update of account , so in that case your plugin will trigger multiple time . So you need to check depth in that case.

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    It is never a good idea to build a plugin logic using depth unless it is required. The depth of the Plugin increases if the same plugin executes from the plugin itself i.e. assuming you have  register a plugin n update and then within the plugin you are updating the same record which will trigger the plugin again and will stuck in infinite loop. Instead you should use filtering while registering plugin and within the plugin, ensure that you are not updating the same field for the same entity.

    I would suggest you to review you plugin registration properties (specialy filtering) and the operations you are doing. You can share your details here to get some suggestions.

    Hope this helps.

  • B K Sharma Profile Picture
    737 on at

    Dear Ravi Thanks for our prompt reply

    My case is exactly same as you mentioned I am doing some integration on the record creation/updation and also updating returned reference id to the same record, So for update case its required to manage depth condition but in case of record creation why its count going to the 3 and my plugin execution don't going inside the plug in code....Means when first time plugin going for execution than context.depth count is 3 which is not understandable for me

    Please correct me or guide me if I am doing something wrong

  • B K Sharma Profile Picture
    737 on at

    yes I am doing update of same record in plugin execution but it is not clear why context.depth count 3 when record is creating and plug in executing first time

  • Suggested answer
    Dynamics365 Rocker Profile Picture
    7,755 on at

    When you create a record from parent context then context.depth count is 2.

    Here you are creating your account from Lead. Lead is parent in your case.

    You can get more idea from below link:

    crmbusiness.wordpress.com/.../stopping-infinite-plugins-with-parameters-depth-and-parentcontext

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    If you have the same plugin for create/update and are also updating the same plugin then i think this is what must be happing.

    1) On create, you plugin is triggering and issuing an update.

    2) With the above update, You will get the Depth as 1, the same plugin trigger again and again issue an update.

    3) With the above update,  You will get the Depth as 2, the same plugin is triggering again and again issue an update.

    3)With the above update,  You will get the Depth as 3, now Depth >= 2 returns tru hence the plugin doesn't update.

    As I mentioned above, while updating a record, create a new instance of an entity and use only the field which are required to be updated and while registering, use attribute filtering.

    docs.microsoft.com/.../include-filtering-attributes-plugin-registration

    community.dynamics.com/.../use-of-filtering-attributes-in-plugin-registration

    Below is the sample update code. Based on this sample, you should not trigger a plugin for the field mentioned in the update code.

    ========

    var entityToUpdate = new Entity("<EntityName>");

    entityToUpdate["<FieldToUpdate>"] = <ValuetoUpdate>;

    service.Update(entityToUpdate);

    ==========

    Hope this helps.

  • B K Sharma Profile Picture
    737 on at

    Correct my parent account is lead and in this case depth should be 2 but in my trace log (also in debugging) its showing depth is 3, Now i am unable to understand what should I do , This plugin was running perfectly before it but now its showing depth 3, is there any settings available regarding depth

    if (context.Depth > 2 )

    {

         return; //Returning if depth count is more than 2

    }

    else

    {

    //Plug in code

    }

  • B K Sharma Profile Picture
    737 on at

    I have same plug in for create and update but in case of account create it is not executing and the reason is depth count is 3, i don't know why this happing right now because same case for create was running perfectly before it

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Do you have the same plugin for account & case entity? If yes, the best practice is to limit the plugin per entity unless you have some common functinality to run on multiple entities.

    If this was working fine before and has stopped then it is possible that some other process workflow, business rule or something else is updating the entity and hence the extra depth is coming from their.

    Hope this helps.

  • B K Sharma Profile Picture
    737 on at

    nuup this plugin only for account create/update operations

    So if there is something link to study how the depth is updated in crm than I can identify the cause but right now it is not possible to understand the issue without knowing where depth is updating

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans