• 首页
  • 栏目
  • CRM
  • Dynamics CRM: 插件输入参数(InputParameters)中的Target属性

Dynamics CRM: 插件输入参数(InputParameters)中的Target属性

  • 2021-11-17
  • Admin

对于插件中不同的消息, 比如: 创建(Create), 更新(Update), 分配(Assign)等, 我们通过Target属性所获取的东西是不一样的.

以创建(Create)消息为例:

  1. // The InputParameters collection contains all the data passed in the message request.
  2. if (context.InputParameters.Contains("Target") &&
  3. context.InputParameters["Target"] is Entity)
  4. {
  5. // Obtain the target entity from the input parameters.
  6. Entity entity = (Entity)context.InputParameters["Target"];
  7. }

这里的entity变量是创建一条记录时所录入的字段, 可以使用contain方法来判断是否在创建时录入了某个字段, 如果创建时没有填写这个字段,那时用Contain方法返回的就是false

  1. if (entity.Contains("<字段>"))
  2. {
  3. // some logic
  4. }

  • 对于更新(Update)消息也是如此, 使用Target属性所获取的实体里面包含的字段, 也只是更新的字段, 没有更新的字段在Contain方法中返回的会是false.

对于其他消息, 我会在以后进行更新.

参考链接:

Understand the data context passed to a plug-in | Microsoft Docsicon-default.png?t=LA92https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/gg309673(v=crm.8)?redirectedfrom=MSDN

CreateRequest Class (Microsoft.Xrm.Sdk.Messages) | Microsoft Docsicon-default.png?t=LA92https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/gg327591(v=crm.8)

UpdateRequest Class (Microsoft.Xrm.Sdk.Messages) | Microsoft Docsicon-default.png?t=LA92https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/gg327638(v=crm.8)

原文:https://blog.csdn.net/hdjStone/article/details/121388690

联系站长

QQ:769220720