Exemplo n.º 1
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            #region Boilerplate
            IWorkflowContext            context        = executionContext.GetExtension <IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory =
                executionContext.GetExtension <IOrganizationServiceFactory>();
            IOrganizationService service =
                serviceFactory.CreateOrganizationService(context.UserId);

            var tracing = executionContext.GetExtension <ITracingService>();
            #endregion

            var  entityIdString = EntityId.Get(executionContext);
            Guid entityId       = Guid.Empty;

            if (!Guid.TryParse(entityIdString, out entityId))
            {
                Succeeded.Set(executionContext, false);
                ErrorMessage.Set(executionContext, $"Guid {entityIdString} is not a valid GUID.");
                return;
            }

            var teamName = TeamName.Get(executionContext);
            using (var ctx = new XrmServiceContext(service))
            {
                var team = (from t in ctx.CreateQuery <Team>()
                            where t.Name == teamName
                            select t).FirstOrDefault();

                if (team == null)
                {
                    Succeeded.Set(executionContext, false);
                    ErrorMessage.Set(executionContext, $"Team {teamName} not found.");
                    return;
                }

                var logicalName = EntityName.Get(executionContext);
                var reference   = (from r in ctx.CreateQuery(logicalName)
                                   where (Guid)r[$"{logicalName}id"] == entityId
                                   select r).FirstOrDefault();

                if (reference == null)
                {
                    Succeeded.Set(executionContext, false);
                    ErrorMessage.Set(executionContext, $"Entity Reference with logical name {logicalName} and id {entityIdString} wasn't found.");
                    return;
                }

                //Assign otherwise
                var assignRequest = new AssignRequest()
                {
                    Assignee = team.ToEntityReference(),
                    Target   = reference.ToEntityReference()
                };
                service.Execute(assignRequest);
            }


            Succeeded.Set(executionContext, true);
        }
Exemplo n.º 2
0
        private bool ValidateParameters(CodeActivityContext executionContext)
        {
            Boolean         Logging     = EnableLogging.Get(executionContext);
            string          LogFilePath = LogFile.Get(executionContext);
            EntityReference Attachment  = AttachmentId.Get(executionContext);
            string          entityName  = EntityName.Get(executionContext);
            string          recordId    = RecordId.Get(executionContext);

            return(true);
        }
Exemplo n.º 3
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            Boolean         Logging     = EnableLogging.Get(executionContext);
            string          LogFilePath = LogFile.Get(executionContext);
            EntityReference Attachment  = AttachmentId.Get(executionContext);
            string          entityName  = EntityName.Get(executionContext);
            string          recordId    = RecordId.Get(executionContext);

            try
            {
                if (Logging)
                {
                    Log("Workflow Execution Start", LogFilePath);
                }
                if (ValidateParameters(executionContext))
                {
                    // Create a CRM Service in Workflow.
                    IWorkflowContext            context        = executionContext.GetExtension <IWorkflowContext>();
                    IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
                    IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);

                    if (Logging)
                    {
                        Log("Attaching Attachment", LogFilePath);
                    }

                    // Create an attachment.
                    Entity UpdatedAttachment = new Entity("annotation");
                    UpdatedAttachment.Id = Attachment.Id;
                    UpdatedAttachment.Attributes.Add("objectid", new EntityReference(entityName, new Guid(recordId)));
                    service.Update(UpdatedAttachment);

                    if (Logging)
                    {
                        Log("Attachment linked successfully", LogFilePath);
                    }

                    if (Logging)
                    {
                        Log("Workflow Executed Successfully", LogFilePath);
                    }
                }
            }
            catch (Exception ex)
            {
                Log(ex.Message, LogFilePath);
            }
        }
Exemplo n.º 4
0
 /// <inheritdoc />
 protected override void Execute(Context context)
 {
     context.Service.Delete(EntityName.Get(context), Guid.Parse(EntityId.Get(context)));
 }
Exemplo n.º 5
0
        /// <inheritdoc />
        protected override void Execute(Context context)
        {
            var service = ExecureAsSystem.Get(context) ? context.SystemService : context.Service;

            context.Service.Delete(EntityName.Get(context), Guid.Parse(EntityId.Get(context)));
        }