如何在Dynamics CRM插件中获取销售订单的父帐户实体?

时间:2012-10-20 23:21:19

标签: dynamics-crm-2011

我正在开发一个附加到CreateOrder实体的Microsoft Dynamics CRM 2011插件。我需要获取Order父帐户,以访问其某些属性。我正在Execute方法中尝试以下代码,但执行时不存在关键字“accountid”。

Entity entity = (Entity)context.InputParameters["Target"]; // A salesorder entity
EntityReference accountRef = (EntityReference)entity.Attributes["accountid"];

插件在后操作阶段注册,以同步模式执行。下图显示了所有配置。

Plugin Registration Config

是否有其他方法可以获得SalesOrder实体的父帐户?

2 个答案:

答案 0 :(得分:2)

SDK文档似乎是一个错误,因为即使我将插件配置为在异步模式下运行, accountid 属性也永远不可用于salesorder实体。我最后通过 customerid 更改 accountid 属性,实际上可以是帐户(默认行为)。这解决了我的问题,我可以参考订单所属的帐户。

Entity entity = (Entity)context.InputParameters["Target"]; // A salesorder entity
EntityReference accountRef = (EntityReference)entity.Attributes["customerid"];
if (accountRef.LogicalName != "account") return;

答案 1 :(得分:0)

这里有两个可能的问题。首先,您的插件是在同步执行模式下注册的,具有Pre-Operation事件管道执行阶段吗? 看看这个设置,可能存在问题。

其次,如果您正确注册了插件,也许您没有在SalesOrder表单上设置ParentAccount,这可能不是问题:)