Exception
:
Unhandled exception:
Exception type: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]
Message: An unexpected error occurred from ISV code.
(ErrorType = ClientError) Unexpected exception from plug-in (Execute): Plugins.InvoiceRowDiscountPostUpdate:
System.TimeoutException: Couldn’t complete execution of the Plugins.InvoiceRowDiscountPostUpdate
plug-in within the 2-minute limit.Detail:
Business
Requirement
When a discount of parent record gets updated, its need to
- Recalculate various tax amount and to update all associated child records.
- Update parent records itself with sum of calculated amount.
Root
Cause Identified
We have Dynamics CRM
Online SYNCHRONOUS plugin that was going on an infinite recursion when updating
itself.
Solution
- We should remove all the attributes that are consider as filtering attribute in triggering the plugin from the entity before we trigger orgproxy.update
In my case, I had an attribute – new_discount
// Remove the discount attribute from the Parent Invoice Row to
stop going in the infinite loop.
if
(parentInvoiceRow.Contains("new_discount"))
parentInvoiceRow.Attributes.Remove("new_discount");
2) The update cannot be a part of ExecuteMultiple, even if
you remove the triggering attribute. Below is self explanatory code
UpdateRequest createRequest =
new UpdateRequest { Target =
singleChildInvoicerow };
requestWithResults.Requests.Add(createRequest);
// Cannot
be a part of Request Multiple - going on an infinite Loop.
// UpdateRequest
parentCreateRequest = new UpdateRequest { Target = parentInvoiceRow };
// requestWithResults.Requests.Add(parentCreateRequest);
//
Execute all the requests in the request collection using a single web method
call - for only Child Record.
ExecuteMultipleResponse responseWithResults
= (ExecuteMultipleResponse)neoService.Execute(requestWithResults);
// Do a
separate update for the parent record.
neoService.Update(parentInvoiceRow);