/// <summary> /// Main code activity function /// </summary> /// <param name="executionContext"></param> /// <param name="crmWorkflowContext"></param> public override void ExecuteCRMWorkFlowActivity(CodeActivityContext executionContext, LocalWorkflowContext crmWorkflowContext) { if (crmWorkflowContext == null) { throw new ArgumentNullException(nameof(crmWorkflowContext)); } TracingService = executionContext.GetExtension <ITracingService>(); Service = crmWorkflowContext.OrganizationService; // 1. Validation var account = this.Account.Get(executionContext); int contactRole = this.ContactRole.Get(executionContext); if (account == null) { TracingService.Trace("Account parameter not set."); return; } if (contactRole < 1) { TracingService.Trace("Contact Role parameter not set."); return; } TracingService.Trace("Getting Contacts for Account {0} and Contact Role : {1}", account.Id, contactRole); // 2. Processing - Query CRM for contacts of a given role and linked to the given account DataAccessContact dataAccess = new DataAccessContact(this.Service, this.TracingService); EntityReference [] contactEntityReferences = dataAccess.GetAccountContacts(account.Id, (Contact_AccountRoleCode)contactRole); // 3. Return contacts found if (contactEntityReferences == null) { // No contacts return; } int contactCount = 0; if (contactEntityReferences.Length > contactCount) { Contact1.Set(executionContext, contactEntityReferences[contactCount++]); } if (contactEntityReferences.Length > contactCount) { Contact2.Set(executionContext, contactEntityReferences[contactCount++]); } if (contactEntityReferences.Length > contactCount) { Contact3.Set(executionContext, contactEntityReferences[contactCount++]); } if (contactEntityReferences.Length > contactCount) { Contact4.Set(executionContext, contactEntityReferences[contactCount++]); } if (contactEntityReferences.Length > contactCount) { Contact5.Set(executionContext, contactEntityReferences[contactCount++]); } if (contactEntityReferences.Length > contactCount) { Contact6.Set(executionContext, contactEntityReferences[contactCount++]); } if (contactEntityReferences.Length > contactCount) { Contact7.Set(executionContext, contactEntityReferences[contactCount++]); } if (contactEntityReferences.Length > contactCount) { Contact8.Set(executionContext, contactEntityReferences[contactCount++]); } if (contactEntityReferences.Length > contactCount) { Contact9.Set(executionContext, contactEntityReferences[contactCount++]); } if (contactEntityReferences.Length > contactCount) { Contact10.Set(executionContext, contactEntityReferences[contactCount++]); } if (contactEntityReferences.Length > contactCount) { Contact11.Set(executionContext, contactEntityReferences[contactCount++]); } if (contactEntityReferences.Length > contactCount) { Contact12.Set(executionContext, contactEntityReferences[contactCount++]); } if (contactEntityReferences.Length > contactCount) { Contact13.Set(executionContext, contactEntityReferences[contactCount++]); } if (contactEntityReferences.Length > contactCount) { Contact14.Set(executionContext, contactEntityReferences[contactCount++]); } if (contactEntityReferences.Length > contactCount) { Contact15.Set(executionContext, contactEntityReferences[contactCount]); } }