Hi All,
I want to retrieve records from child entity (my_child) from opportunity but it runs into infinite loop.
I have registered this plugin on Update of Opportunity field (my_field).
Message:Update
Primary Entity: Opportunity
Filtering Attributes: new_field
Stage:Post-Operation (Synchronous)
My Code
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName != "opportunity")
return;
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
Guid parentId = entity.Id;
var query = new QueryExpression("new_child"); //child entity
query.Criteria.AddCondition(new ConditionExpression("new_opportunity", ConditionOperator.Equal, parentId)); //new_opportunity is the lookup name in child entity
query.ColumnSet = new ColumnSet(true);
var results = service.RetrieveMultiple(query);
if (results.Entities.Any())
{
entity["new_testfee"] = "True";
}
else
{
entity["new_testfee"] = "False";
}
service.Update(entity);
Business Process Error
System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: This workflow job was canceled because the workflow that started it included an infinite loop. Correct the workflow logic and try again. For information about workflow logic, see Help. (Fault Detail is equal to Exception details:
ErrorCode: 0x80044182
Message: This workflow job was canceled because the workflow that started it included an infinite loop. Correct the workflow logic and try again. For information about workflow logic, see Help.
TimeStamp: 2018-10-01T15:54:13.4504671Z
What am I doing wrong?