0
我在CRM 2011中創建一個簡單的插件來自動填充案例解決後的案件關閉日期。爲此,我在Incident實體的「SetState」和「SetStateDynamicEntity」中註冊我的插件。我創建了一個新的日期字段「new_closeddate」來包含該值。客戶關係管理2011年插件來填充案例關閉日期
出於某種原因,我的插件從不會觸發,即使我註冊了幾次並執行了IISReset。任何人都可以請指導我在正確的方向嗎?非常感謝您的幫助。
這是我的代碼如下。
感謝,
-elisabeth
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 });
}