如何知道在 Dynamics CRM 插件上下文中可能有哪些 InputParameters 值?

How to know what InputParameters values are possible in Dynamics CRM Plugin context?

我正在尝试理解 here 中的插件示例。 有这个条件:

// The InputParameters collection contains all the data passed in the message request.
if (context.InputParameters.Contains("Target") &&
                context.InputParameters["Target"] is Entity)

一般来说,不仅仅是关于这个样本,我应该根据哪些先验知识来决定访问特定 属性?我怎么知道要测试 InputParameters 是否包含 "Target" 密钥(我假设我不应该猜到它)?

我凭什么知道 "Target" 映射值是否属于 Entity 类型,而不是其他类型?

我找到 this post from 2 years ago, and I've found this 网页,说(重点是我的):

Within a plugin, the values in context.InputParameters and context.OutputParameters depend on the message and the stage that you register the plugin on. For example, "Target" is present in InputParameters for the Create and Update messages, but not the SetState message. Also, OutputParameters only exist in a Post stage, and not in a Pre stage. There is no single source of documentation that provides the complete set of InputParameters and OutputParameters by message and stage.

根据我的搜索,单一来源仍然不存在,但也许可以使用 Dynamics Online 平台找到可能的值,在“设置”菜单的深处,也许吧?任何来源都很好。

执行此操作的最佳做​​法是使用强类型方法。例如,如果您想知道 CreateRequest 上有哪些属性可用,您可以这样做:

var createReq = new CreateRequest() { Parameters = context.InputParameters };
createReq.Target; // Has type Entity

查看完整的博客 post 解释此方法:Tip: Proper handling of Plugin InputParameters


原回答:

这取决于我们谈论的是哪个请求。请参阅 MSDN 上的 Understand the data context passed to a plug-in

As an example, take a look at CreateRequest. One property of CreateRequest is named Target, which is of type Entity. This is the entity currently being operated upon by the platform. To access the data of the entity you would use the name “Target” as the key in the input parameter collection. You also need to cast the returned instance.

Note that not all requests contain a Target property that is of type Entity, so you have to look at each request or response. For example, DeleteRequest has a Target property, but its type is EntityReference.

总结:查看实际请求,例如 CreateRequest

2011 年实际上有人根据消息类型生成了类型化属性。有点整洁:https://xrmpalmer.wordpress.com/2013/05/27/crm2011-plugin-inputparameter-and-outputparameter-helper/

它会显示您希望每条消息都可以使用参数。

我知道这个 "old" 问题已经得到解答,但我认为这会有所帮助。我建立了一个小网页,其中包含所有带有所有 Input/Output 参数的消息。您可以从 here:

访问它