CRM 2013在关闭消息期间更新事件字段

本文关键字:更新 事件 字段 消息 2013 CRM | 更新日期: 2023-09-27 18:21:12

我正在尝试在案例结束时更新特定字段。我已将插件注册为"关闭"消息上的预操作事件。我注册的活动如下。

base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(20, "Close", "incident", new Action<LocalPluginContext>(ExecutePreCaseCloseFolder)));

在Execute方法中,我有以下代码

Entity incidentResolution = (context.InputParameters != null && context.InputParameters.Contains("IncidentResolution")) ? (Entity)context.InputParameters["IncidentResolution"] : null;
Incident incident = (localContext.OrganizationService.Retrieve("incident", ((EntityReference)incidentResolution["incidentid"]).Id, new Microsoft.Xrm.Sdk.Query.ColumnSet(true))).ToEntity<Incident>();
string documentSetURL = CloseCase(incident);
incident.new_documentSetURL = documentSetURL;

但是,它并没有更新字段。当我关闭一个案例时,我的插件会被触发,我可以调试并查看更新的documentSetURL是否应用于incident.new_documentSetURL.

那么,为什么不更新呢。

如果我没有错的话,预操作是在验证完成之后,但在保存值之前。而且,在保存值之前,我正在更新它。我的理解不正确吗?

CRM 2013在关闭消息期间更新事件字段

事件关闭时无法更新。因此,您必须在创建IncidentSolution之前更新您的案例。

在你的插件中,你必须更新你检索到的案例:service.Update(incident);。这样可以确保在创建事件解决方案之前更新案例。

看看http://nickhollis.blogspot.pt/2013/04/crm-2011-plugin-to-update-case-incident.html.