public override void ExecuteCRMWorkFlowActivity(CodeActivityContext context, LocalWorkflowContext crmWorkflowContext) { crmWorkflowContext.TracingService.Trace("Loaded Supplier Information Workflow Activity"); var supplierInformationUtil = new SupplierInformation(crmWorkflowContext.OrganizationService, crmWorkflowContext.TracingService); var socialInsuranceNumber = SIN.Get(context); if (string.IsNullOrEmpty(socialInsuranceNumber)) { throw new ArgumentNullException("Social Insurance Number cannot be null or blank"); } var supplierInfo = supplierInformationUtil.GetSupplierInformation(SIN.Get(context)); LastName.Set(context, supplierInfo.LastName); crmWorkflowContext.TracingService.Trace($"Last Found: {supplierInfo.LastName}"); SupplierNumber.Set(context, supplierInfo.SupplierNumber); crmWorkflowContext.TracingService.Trace($"Supplier Number: {supplierInfo.SupplierNumber}"); SiteNumber.Set(context, supplierInfo.SupplierSiteNumber); crmWorkflowContext.TracingService.Trace($"Supplier Site Number: {supplierInfo.SupplierSiteNumber}"); MethodOfPayment.Set(context, supplierInfo.MethodOfPayment); crmWorkflowContext.TracingService.Trace($"Method of Payment: {supplierInfo.MethodOfPayment}"); crmWorkflowContext.TracingService.Trace("Custom Workflow Activity Finished"); }
public override void ExecuteCRMWorkFlowActivity(CodeActivityContext context, LocalWorkflowContext crmWorkflowContext) { crmWorkflowContext.TracingService.Trace("Loaded Supplier Information Workflow Activity"); var supplierInformationUtil = new SupplierInformation(crmWorkflowContext.OrganizationService, crmWorkflowContext.TracingService); var socialInsuranceNumber = SIN.Get(context); if (string.IsNullOrEmpty(socialInsuranceNumber)) { throw new ArgumentNullException("Social Insurance Number cannot be null or blank"); } var supplierInfo = supplierInformationUtil.GetSupplierInformation(SIN.Get(context)); crmWorkflowContext.TracingService.Trace($"SupplierInfo: {supplierInfo.ID}"); if (supplierInfo.ID == Guid.Empty) { crmWorkflowContext.TracingService.Trace("SIN not found in the CAS Supplier Lookup records"); //Populate entity reference with random GUID to avoid the workflow crash. Dynamics Bug. Microsoft needs to make fix. EntityReference CASSupplierLookupRef = new EntityReference("educ_cassupplierlookup", Guid.NewGuid()); CASSupplierRef.Set(context, CASSupplierLookupRef); crmWorkflowContext.TracingService.Trace($"CASSupplierLookupRef: {supplierInfo.ID}"); PartyId.Set(context, -1); } else { EntityReference CASSupplierLookupRef = new EntityReference("educ_cassupplierlookup", supplierInfo.ID); CASSupplierRef.Set(context, CASSupplierLookupRef); crmWorkflowContext.TracingService.Trace($"CASSupplierLookupRef: {supplierInfo.ID}"); PartyId.Set(context, supplierInfo.PartyID); crmWorkflowContext.TracingService.Trace($"PartyID: {supplierInfo.PartyID}"); LastName.Set(context, supplierInfo.LastName); crmWorkflowContext.TracingService.Trace($"Last Found: {supplierInfo.LastName}"); SupplierNumber.Set(context, supplierInfo.SupplierNumber); crmWorkflowContext.TracingService.Trace($"Supplier Number: {supplierInfo.SupplierNumber}"); SiteNumber.Set(context, supplierInfo.SupplierSiteNumber); crmWorkflowContext.TracingService.Trace($"Supplier Site Number: {supplierInfo.SupplierSiteNumber}"); MethodOfPayment.Set(context, supplierInfo.MethodOfPayment); crmWorkflowContext.TracingService.Trace($"Method of Payment: {supplierInfo.MethodOfPayment}"); crmWorkflowContext.TracingService.Trace("Custom Workflow Activity Finished"); } }
protected override void Execute(CodeActivityContext executionContext) { //Create the tracing service ITracingService tracingService = executionContext.GetExtension <ITracingService>(); //Create the context IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); tracingService.Trace("Loaded UpsertSupplierWorkflow"); tracingService.Trace("CREATING Contact object with the input values"); tracingService.Trace("Checkpoint 1"); Contact contact = new Contact(); int partyid = PartyID.Get <int>(executionContext); tracingService.Trace("Starting assigning attribute variables."); contact.First_Name = FirstName.Get <string>(executionContext).ToString(); tracingService.Trace("First Name Populated"); tracingService.Trace(string.Format("Setting party id = {0}", partyid)); contact.Party_Id = partyid; tracingService.Trace("Party ID populated"); contact.Last_Name = LastName.Get <string>(executionContext).ToString(); tracingService.Trace("Last Name Populated"); contact.Payment_Method = PaymentMethod.Get <string>(executionContext).ToString(); tracingService.Trace("Payment Method Populated"); contact.SIN = SIN.Get <string>(executionContext).ToString(); tracingService.Trace("SIN Populated"); contact.Address1 = Address1.Get <string>(executionContext).ToString(); tracingService.Trace("Address1 Populated"); contact.Country_Code = Country.Get <string>(executionContext).ToString(); tracingService.Trace("Country Populated"); contact.City = City.Get <string>(executionContext).ToString(); tracingService.Trace("City Populated"); contact.Province_Code = Province.Get <string>(executionContext).ToString(); tracingService.Trace("Province Populated"); contact.Postal_Code = PostalCode.Get <string>(executionContext).ToString(); tracingService.Trace("Postal Code Populated"); tracingService.Trace("Checkpoint 2"); EntityReference contactRef = ContactReference.Get <EntityReference>(executionContext); contact.ID = contactRef.Id; tracingService.Trace("Fetching the Configs"); ////Get the configuration record for Oracle_T4A group from the configs entity and get the connection value from the record. var configs = Helper.GetSystemConfigurations(service, ConfigEntity.Group.ORACLE_T4A, string.Empty); tracingService.Trace("Fetching Connection"); string connection = Helper.GetConfigKeyValue(configs, ConfigEntity.Key.CONNECTION, ConfigEntity.Group.ORACLE_T4A); try { tracingService.Trace("Fetching Oracle Response by making call to Helper.UpsertSupplierInOracle()"); OracleResponse response = Helper.UpsertSupplierInOracle(contact, connection, tracingService); if (response.TransactionCode == OracleResponse.T4A_STATUS.OK) { tracingService.Trace("Inside OracleResponse.T4A_STATUS.OK \nRetriving and setting response values to output"); PartyID.Set(executionContext, response.PartyId); tracingService.Trace("Party ID Output Param is set"); } tracingService.Trace("Setting up transaction code and transaction message"); TransactionCode.Set(executionContext, response.TransactionCode.Trim()); TransactionMessage.Set(executionContext, response.TransactionMessage); } catch (InvalidWorkflowException ex) { Helper.LogIntegrationError(service, ErrorType.CONTACT_ERROR, IntegrationErrorCodes.UPSERT_SUPPLIER.GetIntValue(), Strings.T4A_FER_ERROR, string.Format("Error Description: {0} ", ex.Message), contactRef); } catch (Exception ex) { Helper.LogIntegrationError(service, ErrorType.CONTACT_ERROR, IntegrationErrorCodes.UPSERT_SUPPLIER.GetIntValue(), Strings.T4A_FER_ERROR, string.Format("Error Description: {0} ", ex.Message), contactRef); } }