【发布时间】:2013-04-12 20:04:53
【问题描述】:
重新表述的问题(4 月 24 日):
我正在使用 VS2012 的 CRM Developer Toolkit 创建一个 CRM2011 插件。该插件为“发票产品”实体的CREATE 消息注册。 Pipeline-Stage 是后期操作,执行是同步的。我注册了一个包含baseamount的帖子图片。
该工具包创建一个如下所示的执行函数:
protected void ExecutePostInvoiceProductCreate(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}
IPluginExecutionContext context = localContext.PluginExecutionContext;
Entity postImageEntity = (context.PostEntityImages != null && context.PostEntityImages.Contains(this.postImageAlias)) ? context.PostEntityImages[this.postImageAlias] : null;
}
既然处于后期运算阶段,postImageEntity 中的baseamount 的值应该已经从用户输入中计算出来了吧?但是,postImageEntity 中的baseamount 的值为零。我使用以下代码获得的目标实体中baseamount 的值也是如此:
Entity targetEntity = (context.InputParameters != null && context.InputParameters.Contains("Target")) ? (Entity)context.InputParameters["Target"] : null;
使用如下所示的检索请求,我得到了正确的 baseamount 值:
Entity newlyCreated = service.Retrieve("invoicedetail", targetEntity.Id, new ColumnSet(true));
decimal baseAmount = newlyCreated.GetAttributeValue<Money>("baseamount").Value;
该问题不会出现在更新事件的后期运行阶段。
我很高兴听到你关于为什么会这样的想法/解释/建议......
(更多信息:远程调试,无隔离模式,插件存储在数据库中)
原问题:
我正在为 CRM 2011 开发一个插件,该插件应该在创建发票详细信息时计算要支付的税额。为此,我试图在后期操作阶段从后期实体图像中获取新创建的invoicedetail实体的baseamount。据我了解,发布实体图像是创建新发票详细信息后数据库中实体的快照。因此它应该包含新创建的发票明细的所有属性。
我获得了 IPluginExecutionContext 的“postentityimages”属性,其中包含一个具有我注册的别名(“postImage”)的实体。这个“postImage”实体包含一个“baseamount”的键,但它的值为 0。谁能帮我理解为什么会这样以及我能做些什么?
(我还注意到 postImage 不包含我注册的所有实体,而只包含我注册的实体的一个子集。)
代码如下:
protected void ExecutePostInvoiceProductCreate(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}
// Get PluginExecutionContext to obtain PostEntityImages
IPluginExecutionContext context = localContext.PluginExecutionContext;
// This works: I get a postImage that is not null.
Entity postImage = (context.PostEntityImages != null && context.PostEntityImages.Contains(this.postImageAlias)) ? context.PostEntityImages[this.postImageAlias] : null;
// Here is the problem: There is a "baseamount" key in the postImage
// but its value is zero!
decimal baseAmount = ((Money)postImage["baseamount"]).Value;
}
添加:用于后期操作更新的前后图像包含非零值的 baseamount。
【问题讨论】:
-
您是在本地调试以找出值吗?
-
不,我正在使用“调试”菜单中的“附加到进程...”进行远程调试。顺便说一句,我在调试器中得到了正确的“数量”值,但“基本数量”为零。
-
要么该值被其他插件设置为 0,要么没有设置为其他值。由于您正在调试它,请执行一个简单的retrieveEntity 请求来获取新创建的记录,并检查它的baseamount 只是为了查看PostImage 是否有错误,或者在插件运行时是否有其他东西将值更改为0。
-
我通过以下方式检索到新创建的记录:
Entity newlyCreated = service.Retrieve("invoicedetail", targetEntity.Id, new ColumnSet(true));在newlyCreated中baseamount 的值是正确的。因此,我猜 PostImage 有问题。 -
Target 上的值是否正确?
标签: plugins dynamics-crm-2011 crm