Why is CRM 2011 Entity Relationship null in this plugin code?

后端 未结 1 1056
走了就别回头了
走了就别回头了 2021-01-20 09:44

this is a working example of a plugin that I have written for CRM 2011. I have created a \'Create\' step in the plugin registration tool for this plugin. This executes fin

相关标签:
1条回答
  • 2021-01-20 10:27

    The entity contained in the InputParameters["Target"] only includes the changed fields that were submitted in the update, not all fields. Your plugin works for Create because InputParameters["Target"] always contains all fields during a Create obviously.

    To fix this, you need to add a PreImage to your step in PluginRegistrationTool that includes the primarycontactid field. A PreImage will always include the values for the fields you specify as they were before the update.

    The trick is to check for primarycontactid on InputParameters["Target"] first, because that would contain the latest value (if the user updated both new_receivesnewsletter and primarycontactid during the same save, for example). If InputParameters["Target"] doesn't contain primarycontactid, then fall back on your PreImage, accessed something like this (assuming you set your PreImage's alias to "preimage"):

    context.PreEntityImages["preimage"].GetAttributeValue<EntityReference>("primarycontactid")
    

    Hope that helps!

    0 讨论(0)
提交回复
热议问题