【发布时间】:2014-04-08 17:22:26
【问题描述】:
我正在 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 });
}
【问题讨论】: