7

How can it be determined in a synchronous plug-in which fields changed?
The plug-in is registered on update.
Something like an isDirty() in JavaScript:

// TODO: Implement your custom Plug-in business logic.
IOrganizationService service = localContext.OrganizationService;
Entity account = (Entity)localContext.PluginExecutionContext.InputParameters["Target"];
if (account.GetAttributeValue<String>("address1_latitude").isDirty())
{
    service.Create(new Lead { FirstName = "LOCATION CHANGED" }); // this is a stub
} 

2 Answers 2

15

The attributes that are actually present in the Target are the ones that have changed. Unchanged attributes don't appear there.

3
14

I'm going to expand on GCATNM's answer slightly. The Target contains all the values that were included in the update request, not just values that are different than what currently exists in the DB.

Unless you perform some extremely "hacky" JavaScript on the form, the target entity of updates / creates from the CRM web front end will always only contain the values that have changed, since the JavaScript in the CRM UI will only send in the values that have changed.

But, if you are updating the data via some other method (OData call, C# update using the SDK) and values are included in the update request that haven't actually changed, they will show up in the Target of the plugin. For example, if you have a C# process that grabs all the attributes for a specific entity, then updates a single attribute, all attributes for the entity will show up in the target.

So really the target isn't what has changed, but what the entity will be after the plugin completes. You'll need to included the attributes in the pre-image that you'd like to inspect for changes in order to be able to determine if the value really has changed.

3
  • Your answer is extremely relevant. I am updating gps co-ords via Resco Mobile CRM; the plug-in fires when lat, or long change and proves that the sales rep was at the location. It seems that in this case all the field values will be found in localContext.PluginExecutionContext.InputParameters["Target"], so I will compare the pre-image values to the ["Target"] values to ascertain whether they have changed.
    – Bvrce
    Commented Mar 26, 2013 at 13:40
  • Basically, the Target contains values sent to the server. Not necessarily "changed". Just exactly what was included in the request (e.g. Update or Create) Commented Aug 7, 2020 at 21:58
  • Isn't that what I said? Maybe I should fix some wording?
    – Daryl
    Commented Aug 8, 2020 at 1:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.