编程语言
首页 > 编程语言> > c# – CRM 2011 PLUGIN – PostTaskSetState

c# – CRM 2011 PLUGIN – PostTaskSetState

作者:互联网

我正在创建一个插件,当用户在crm中设置任务的状态时,验证与事件关联的所有任务.如果没有打开任务,则应该关闭事件.

当我使用配置文件调试插件时,它工作正常,但没有任何反应.

 IPluginExecutionContext context = localContext.PluginExecutionContext;
            IOrganizationService service = localContext.OrganizationService;
            EntityReference entity = (EntityReference)context.InputParameters["EntityMoniker"];
            ColumnSet cols = new ColumnSet();
            cols.AllColumns = true;
            Entity entityComplete = service.Retrieve("task", entity.Id, cols);

            if (((OptionSetValue)entityComplete.Attributes["statecode"]).Value == 0) //se o status for cancelado ou concluído
            {
                if (entityComplete.Attributes.Keys.Contains("regardingobjectid") && ((EntityReference)entityComplete.Attributes["regardingobjectid"]).LogicalName == "incident")
                {

                    QueryExpression query = new QueryExpression();
                    query.EntityName = "task";
                    query.ColumnSet = cols;
                    query.LinkEntities.Add(new LinkEntity("task", "incident", "regardingobjectid", "incidentid", JoinOperator.Inner));
                    query.Criteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, 0));
                    query.Criteria.AddCondition(new ConditionExpression("activityid", ConditionOperator.NotEqual, entityComplete.Id));
                    query.Criteria.AddCondition(new ConditionExpression("regardingobjectid", ConditionOperator.Equal, ((EntityReference)entityComplete.Attributes["regardingobjectid"]).Id));
                    EntityCollection collection = service.RetrieveMultiple(query);
                    if (collection.Entities.Count == 0)
                    {
                        Entity incident = service.Retrieve("incident", ((EntityReference)entityComplete.Attributes["regardingobjectid"]).Id, cols);
                        SetStateRequest setState = new SetStateRequest();
                        setState.EntityMoniker = new EntityReference();
                        setState.EntityMoniker.Id = incident.Id;
                        setState.EntityMoniker.LogicalName = incident.LogicalName;
                        setState.State = new OptionSetValue(1);
                        SetStateResponse setStateResponse = (SetStateResponse)service.Execute(setState);
                    }
                }
            }

有人可以帮帮我吗?
谢谢.

解决方法:

尝试为SetStateDynamicEntity消息注册插件,此外还要为SetState执行相同的操作.根据我的经验,实体需要注册才能工作,虽然我不是100%明确是否有必要,但我知道它有效.几次搜索没有给我一个确定的答案.查看这个受欢迎的CRM博客与相同的建议. http://nishantrana.wordpress.com/2010/01/29/plug-in-for-setstate-and-setstatedynamicentity-messages/

我知道我使用过的实体,未能注册SetStateDynamic会导致插件无法触发.

标签:c,plugins,crm,dynamics-crm,dynamics-crm-2011
来源: https://codeday.me/bug/20190709/1409063.html