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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Plugin recursion in MS CRM

(0) ShareShare
ReportReport
Posted on by 122

Hi experts,

I have a query on the recursion of plugins. By default the maximum allowed loop for recursion is 8.

In my scenario I have self referential entity, used to maintain some configuration data for different business units.By default when I create a configuration record for the top BU it should get created for all the BU's under it and on update of the data on the parent record should also update all the records under it.

To achieve this we created a plugin which will be triggered on Create and Update of record.

when first record is created,on post create it finds the child BU's of the current BU and creates the record for the child in a loop and this Plugin will be called for all the child BU's till it creates the record for last child.

We have similar BU structure in all environments, but this Plugin is working in only some environments . In other environments we are getting exception at 8th time calling.

Do you see any issues here or any suggestions to re implement the logic in a different way would be appreciated.

Thanks!

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at
    RE: Plugin recursion in MS CRM

    Hi Anand,

    to solve the problem you could proceed as follows:

    1) Create a function like the following:

    public void GetChildEntityByParentId(IOrganizationService crmService, List<Entity> entityList, Guid parentBU)
    {
    	QueryByAttribute query = new QueryByAttribute("businessunit");
    	query.ColumnSet = new ColumnSet("businessunitid");
    	query.Attributes.AddRange("parentbusinessunitid");
    	query.Values.AddRange(parentBU);
    	List<Entity> list = crmService.RetrieveMultiple(query).Entities.ToList();
    	
    	entityList.AddRange(list);
    	
    	foreach (Entity entity in list)
    	{
    		GetChildEntityByParentId(crmService, entityList, entity.Id);
    	}
    }

    2) Thanks to this function you will have all the bu's entity listed in one shot

    3) Loop bu's to add the logic you need

    Please let me know if you solve.

    If you found the answer helpful, please mark as Verified 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Plugin recursion in MS CRM

    Hi Anand,

    The default depth (8) is configurable by the Microsoft Dynamics 365 administrator using the PowerShell command Set-CrmSetting. The setting is WorkflowSettings.MaxDepth.

    Check the below links-

    technet.microsoft.com/.../dn531194.aspx

    blog.dorrekens.com/.../137-mscrm-infinite-loop-for-plugins

    Hope this helps

  • Community Member Profile Picture
    on at
    RE: Plugin recursion in MS CRM

    Hi Anand,

    if you solved the problem thanks to an answer, please mark it as verified to encourage the community to provide more and more a better support. Thank you. Francesco

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Anand Kumar M Profile Picture
    122 on at
    RE: Plugin recursion in MS CRM

    Hi Francesco Picchi,

    As the plugin was registered on Create of each BU's related record, I checked the

    depth and returned from the Plugin if it is more than 1 and it worked perfectly.

    Thanks for your suggestion.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans