Infinite Loop When Overriding Order Recalculate RRS feed

  • Question

  • Hi There,

    I try to override the recalculate behavior of CRM sales orders because I've added custom discount fields in both salesorder and salesorderdetail. This is what I've done already:

    1. Create a pre-processing plugin on create/update of salesorderdetail which recalculates the salesorderdetail fields
    2. Create a pre-processing plugin on update of salesorder which recalculates the salesorder fields. Here I also perform a lookup for related salesorderdetail records to get the required values, but I do not update those salesorderdetail records.

    I'm already working on this for a week and cannot find a solution that works.

    For some reason I have an infinite loop because the Depth parameter increases until 8 and then it throws an exception. Next to that, CRM seems to overwrite my calculation....

    Can someone PLEASE explain to me how I can get this working?

    Wednesday, February 20, 2013 6:05 PM

All replies

  • You should post your plugin code for both so we can try to see what is causing the recursion.

    Jamie Miley

    Check out RBA Today!

    Check out my about.me profile!
    Linked-In Profile
    Follow Me on Twitter!

    Wednesday, February 20, 2013 6:15 PM
  • Let's start with salesorderdetail, which by it's own doesn't work.  Using the plugin registration tool I disabled all salesorder steps at the mean time.

    I probably make the same mistake twice

    // The InputParameters collection contains all the data passed in the message request. if (ipxContext.InputParameters.Contains("Target") && ipxContext.InputParameters["Target"] is Entity) { // Obtain the target entity from the input parmameters. Entity entOrderProdInput = (Entity)ipxContext.InputParameters["Target"]; //If we are in an update stage and missing vars for later calculations, //look them up and add them to the entity if (ipxContext.MessageName == "Update") { string[] strColumnsOrderProduct = new string[] { "productid", "uomid", "salesorderid", "uip_manualdiscountamount", "volumediscountamount", "priceperunit", "quantity" }; Entity entOrderProductTemp = iosService.Retrieve("salesorderdetail", entOrderProdInput.Id, new ColumnSet(strColumnsOrderProduct)); if (!entOrderProdInput.Attributes.Contains("productid") && entOrderProductTemp.Attributes.Contains("productid")) entOrderProdInput.Attributes.Add("productid", entOrderProductTemp.Attributes["productid"]); if (!entOrderProdInput.Attributes.Contains("uomid") && entOrderProductTemp.Attributes.Contains("uomid")) entOrderProdInput.Attributes.Add("uomid", entOrderProductTemp.Attributes["uomid"]); } // Here is perform my field calculation, nothing special. All the vars like monVolDiscount are inited in this hidden (long) code block // Set Output: Volume Discount if (entOrderProdInput.Attributes.Contains("volumediscountamount")) entOrderProdInput["volumediscountamount"] = monVolDiscount; else entOrderProdInput.Attributes.Add("volumediscountamount", monVolDiscount); // Set Output: Manual Discount if (entOrderProdInput.Attributes.Contains("uip_manualdiscountamount")) entOrderProdInput["uip_manualdiscountamount"] = monManDiscount; else entOrderProdInput.Attributes.Add("uip_manualdiscountamount", monManDiscount); // Set Output Subtotal if (entOrderProdInput.Attributes.Contains("baseamount")) entOrderProdInput["baseamount"] = monSubTotal; else entOrderProdInput.Attributes.Add("baseamount", monSubTotal); // Set Output: Tax if (entOrderProdInput.Attributes.Contains("tax")) entOrderProdInput["tax"] = monTax; else entOrderProdInput.Attributes.Add("tax", monTax); // Set Output: Total if (entOrderProdInput.Attributes.Contains("extendedamount")) entOrderProdInput["extendedamount"] = monTotal; else entOrderProdInput.Attributes.Add("extendedamount", monTotal);


    • Edited by BigAristotle Wednesday, February 20, 2013 6:42 PM
    Wednesday, February 20, 2013 6:40 PM
  • Hi,

    Is it your complete code ?, for me it seems you are calling some other service method (may be on which you have a plugin registered) so it's running in the same transaction resulting increasing depth. Share you complete code and provide information on all the related plugin registration steps.

    Contact Me
    Follow me on Twitter
    My Facebook Page
    Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Wednesday, February 20, 2013 7:42 PM
  • That's not my complete code but it explains what I'm doing:

    1. Using ioSService.Retrieve to get missing input entity attributes, required for later calculation
    2. Add the missing fields to entOrderProductInput
    3. Make the calculation
    4. Put the calculated results in entOrderProductInput

    I'm not sure why the calculation itself, which makes no calls to entities, is required here.

    Thursday, February 21, 2013 5:02 AM
  • ur using message as update and operation-preoperation

    when use the preoperation the values are not store into database after the core operation

    u need to check inputparameter and update the values

    ms crm

    Thursday, February 21, 2013 9:17 AM
  • 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.

    Regards Faisal

    Thursday, February 21, 2013 10:25 AM
  • Thanks for the replies.

    @Dicaprio r: Can you go a bit more into detail, I do not really understand what you try to say.

    @Faisal Fiaz: What do you exactly mean with a "message request to the web services"? As far as I know I only issue a retrieve call which shouldn't trigger any other plugins?  I do not understand which plugin gets called causing the depth to increase...

    Thursday, February 21, 2013 12:34 PM
  • nobody with more information?
    Monday, February 25, 2013 1:50 PM
  • Hi,

    I would avoid updating the salesorder record in a salesorderdetail plugin step vice versa. When an amount field on salesorderdetail level is modified, the CRM system performs an automatic update of the related salesorder record.

    For more detailed help I would need to see more of your code.



    If this post is an answer or helpful, please do not forget to vote!

    Wednesday, February 27, 2013 2:13 PM
  • Put these line in your plugin:

    if (context.Depth > 1)

    Check this article


    Regards Faisal

    Wednesday, February 27, 2013 2:50 PM