Plugins CRM 2011插件用于填充案例结束日期

Plugins CRM 2011插件用于填充案例结束日期,plugins,crm,Plugins,Crm,我在CRM 2011中创建了一个简单的插件,当一个案例得到解决时,它会自动填充案例结束日期。为此,我在事件实体的“SetState”和“SetStateDynamicEntity”中注册了我的插件。我创建了一个新的日期字段“new_closeddate”来包含该值 出于某种原因,我的插件从未启动过,尽管我注册了好几次并进行了IISReset。谁能给我指一下正确的方向吗?非常感谢你的帮助 下面是我的代码 谢谢 -伊丽莎白 public override void OnExecute(IServic

我在CRM 2011中创建了一个简单的插件,当一个案例得到解决时,它会自动填充案例结束日期。为此,我在事件实体的“SetState”和“SetStateDynamicEntity”中注册了我的插件。我创建了一个新的日期字段“new_closeddate”来包含该值

出于某种原因,我的插件从未启动过,尽管我注册了好几次并进行了IISReset。谁能给我指一下正确的方向吗?非常感谢你的帮助

下面是我的代码

谢谢

-伊丽莎白

public override void OnExecute(IServiceProvider serviceProvider, IPluginExecutionContext context)
    {
        var trace = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

        // The InputParameters collection contains all the data passed in the message request.
        var targetReference = context.GetParameterCollection<EntityReference>(context.InputParameters, "EntityMoniker");

        if (targetReference == null)
            throw new InvalidPluginExecutionException(OperationStatus.Failed, "Target Entity cannot be null");

        var state = (OptionSetValue)context.InputParameters["State"];

        /* Only proceed if Incident is being set to Resolved */
        if (state == null || state.Value != 1)
            return;      

        var postImage = context.PostEntityImages["PostImage"];

        if (postImage == null)
            throw new InvalidPluginExecutionException(OperationStatus.Failed, "Post Image is required");

        var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
        var service = serviceFactory.CreateOrganizationService(context.UserId);

        Entity CaseIncident = new Entity("incident");
        CaseIncident.Attributes = new AttributeCollection();
        CaseIncident.Attributes.Add("new_closeddate", DateTime.Now);

    }

    protected override bool CanExecute(IPluginExecutionContext context)
    {
        return context.PreConditionCheck(
            0,
            new List<int> { MessageProcessingStage.AfterMainOperationInsideTransaction },
            new List<string> { MessageName.Update },
            new List<string> { Schema.Incident.EntityLogicalName });
    }
public override void OnExecute(IServiceProvider服务提供程序,IPluginExecutionContext上下文)
{
var trace=(ITracingService)serviceProvider.GetService(typeof(ITracingService));
//InputParameters集合包含消息请求中传递的所有数据。
var targetReference=context.GetParameterCollection(context.InputParameters,“EntityMoniker”);
if(targetReference==null)
抛出新的InvalidPluginExecutionException(OperationStatus.Failed,“目标实体不能为null”);
var state=(OptionSetValue)context.InputParameters[“state”];
/*仅当事件设置为“已解决”时才继续*/
if(state==null | | state.Value!=1)
返回;
var postImage=context.PostEntityImages[“postImage”];
if(positmage==null)
抛出新的InvalidPlugineExecutionException(OperationStatus.Failed,“需要后期映像”);
var serviceFactory=(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var service=serviceFactory.CreateOrganizationService(context.UserId);
实体案例事件=新实体(“事件”);
CaseIncident.Attributes=新的AttributeCollection();
CaseIncident.Attributes.Add(“new_closeddate”,DateTime.Now);
}
受保护的覆盖布尔CanExecute(IPluginExecutionContext上下文)
{
返回context.premissioncheck(
0,
新列表{MessageProcessingStage.AfterMainOperationsSideTransaction},
新列表{MessageName.Update},
新列表{Schema.Incident.EntityLogicalName});
}

尝试处理关闭消息,而不是SetState/SetStateDynamicEntity