Hi,
I have created a custom workflow to updated related contacts for an account and everything works fine.The only issue that I am having is that in system logs I am able to get log for(WORKFLOW) once and 97 System Events that updates my field in the contacts.
I have been searching a long through this but I am unable to find this.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Activities; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Workflow; using Microsoft.Xrm.Sdk.Query; namespace RelatedContact_CWA { public class Class1 : CodeActivity { protected override void Execute(CodeActivityContext context) { ITracingService tracingservice = (ITracingService)context.GetExtension<ITracingService>(); IWorkflowContext workflowcontext = context.GetExtension<IWorkflowContext>(); IOrganizationServiceFactory servicefactory = context.GetExtension<IOrganizationServiceFactory>(); IOrganizationService _orgservice = servicefactory.CreateOrganizationService(workflowcontext.InitiatingUserId); try { Guid currentid = workflowcontext.PrimaryEntityId; QueryExpression query = new QueryExpression("account"); query.Criteria = new FilterExpression(); query.ColumnSet = new ColumnSet(true); var account = _orgservice.RetrieveMultiple(query); var accountres = _orgservice.RetrieveMultiple(query); foreach (var res in accountres.Entities) { QueryExpression qe = new QueryExpression("contact"); qe.Criteria = new FilterExpression(); qe.ColumnSet = new ColumnSet(true); qe.Criteria.AddCondition("parentcustomerid", ConditionOperator.Equal, currentid); var contactres = _orgservice.RetrieveMultiple(qe); if (contactres != null && contactres.Entities.Count > 0) { foreach (var subgridrecord in contactres.Entities) { var name = subgridrecord["fullname"].ToString(); Console.WriteLine(name); subgridrecord["jobtitle"] = "developer"; _orgservice.Update(subgridrecord); tracingservice.Trace("Update success"); } } } } catch (Exception e) { Console.WriteLine("error"); } } } } Please advise on this.
Regards,
AxTechie2120
*This post is locked for comments