示例#1
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            // Extract the tracing service
            ITracingService tracingService = executionContext.GetExtension <ITracingService>();

            try
            {
                //Create the context
                IWorkflowContext            context        = executionContext.GetExtension <IWorkflowContext>();
                IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
                IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);

                // Don't Really Care about which entity this is
                DynamicUrlParser parser        = new DynamicUrlParser();
                EntityReference  primaryEntity = parser.ConvertToEntityReference(service, RecordUrl.Get <string>(executionContext));

                string addressLine1    = Street1.Get <string>(executionContext);
                string addressLine2    = Street2.Get <string>(executionContext);
                string city            = City.Get <string>(executionContext);
                string stateOrProvince = StateOrProvince.Get <string>(executionContext);
                string zipCode         = ZipPostalCode.Get <string>(executionContext);
                string countryName     = Country.Get <string>(executionContext);

                string rc = GenerateAddress(addressLine1, addressLine2, city, stateOrProvince, zipCode, countryName);
                FullAddress.Set(executionContext, rc);
            }
            catch (FaultException <OrganizationServiceFault> ex)
            {
                throw new Exception("SBS.Workflow.SetStateChildRecords: " + ex.Message);
            }
        }
示例#2
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            // Extract the tracing service
            ITracingService tracingService = executionContext.GetExtension <ITracingService>();

            try
            {
                //Create the context
                IWorkflowContext            context        = executionContext.GetExtension <IWorkflowContext>();
                IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
                IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);

                DynamicUrlParser parser        = new DynamicUrlParser();
                EntityReference  currentRecord = parser.ConvertToEntityReference(service, RecordUrl.Get <string>(executionContext));

                Guid processId = RetrieveProcessId(service, Process.Get <string>(executionContext));
                if (processId != Guid.Empty)
                {
                    Guid stageId = RetrieveStageId(service, processId, ProcessStage.Get <string>(executionContext));
                    if (stageId != Guid.Empty)
                    {
                        UpdateStage(service, currentRecord, processId, stageId);
                    }
                }
            }
            catch (FaultException <OrganizationServiceFault> ex)
            {
                throw new Exception("XrmWorkflowTools.ChangeProcessStage.Execute: " + ex.Message);
            }
            catch (System.Exception ex)
            {
                throw new Exception("XrmWorkflowTools.ChangeProcessStage.Execute: " + ex.Message);
            }
        }
        protected override void Execute(CodeActivityContext executionContext)
        {
            // Extract the tracing service
            ITracingService tracingService = executionContext.GetExtension <ITracingService>();

            try
            {
                //Create the context
                IWorkflowContext            context        = executionContext.GetExtension <IWorkflowContext>();
                IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
                IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);

                DynamicUrlParser parser           = new DynamicUrlParser();
                EntityReference  primaryEntity    = parser.ConvertToEntityReference(service, RecordUrl.Get <string>(executionContext));
                string           relationshipName = RelationshipName.Get <string>(executionContext);

                string childEntityName = null, childEntityAttribute = null;
                if (relationshipName.Contains(';'))
                {
                    string[] relationshipNames = relationshipName.Split(';');
                    foreach (string rel in relationshipNames)
                    {
                        OneToManyRelationshipMetadata oneToNRelationship = RetrieveRelationshipInfo(service, primaryEntity, relationshipName);
                        if (oneToNRelationship != null)
                        {
                            childEntityName      = oneToNRelationship.ReferencingEntity;
                            childEntityAttribute = oneToNRelationship.ReferencingAttribute;
                            RetrieveAndUpdateRelatedRecords(service, primaryEntity, childEntityName, childEntityAttribute, StateCode.Get <int>(executionContext), StatusCode.Get <int>(executionContext));
                        }
                    }
                }
                else
                {
                    OneToManyRelationshipMetadata oneToNRelationship = RetrieveRelationshipInfo(service, primaryEntity, relationshipName);
                    if (oneToNRelationship != null)
                    {
                        childEntityName      = oneToNRelationship.ReferencingEntity;
                        childEntityAttribute = oneToNRelationship.ReferencingAttribute;
                        RetrieveAndUpdateRelatedRecords(service, primaryEntity, childEntityName, childEntityAttribute, StateCode.Get <int>(executionContext), StatusCode.Get <int>(executionContext));
                    }
                }
            }
            catch (FaultException <OrganizationServiceFault> ex)
            {
                throw new Exception("XrmWorkflowTools.SetStateChildRecords: " + ex.Message);
            }
        }
示例#4
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            // Extract the tracing service
            ITracingService tracingService = executionContext.GetExtension <ITracingService>();

            try
            {
                //Create the context
                IWorkflowContext            context        = executionContext.GetExtension <IWorkflowContext>();
                IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
                IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);

                DynamicUrlParser parser      = new DynamicUrlParser();
                EntityReference  refEntity   = parser.ConvertToEntityReference(service, RecordUrl.Get <string>(executionContext));
                EntityReference  refTemplate = EmailTemplate.Get <EntityReference>(executionContext);


                Guid   emailId     = CreateTemplatedEmail(service, refEntity, refTemplate.Id);
                Entity email       = service.Retrieve("email", emailId, new ColumnSet("description"));
                string description = email.Contains("description") ? email.GetAttributeValue <string>("description") : string.Empty;

                List <Entity>   fromList   = new List <Entity>();
                EntityReference systemUser = Sender.Get <EntityReference>(executionContext);
                Entity          user       = new Entity("activityparty");
                user["partyid"] = systemUser;
                fromList.Add(user);

                UpdateEmailMessage(service, emailId, refEntity, fromList);
                EmailMessage.Set(executionContext, new EntityReference("email", emailId));
            }
            catch (FaultException <OrganizationServiceFault> ex)
            {
                throw new Exception("XrmWorkflowTools.CreateEmailFromTemplate: " + ex.Message);
            }
            catch (System.Exception ex)
            {
                throw new Exception("XrmWorkflowTools.CreateEmailFromTemplate: " + ex.Message);
            }
        }