views:

358

answers:

5

I have a MS CRM 4 form where when certain fields are changed, I need those fields to be written to an excel sheet.

So, I edited the form field onchange event to call crmform.save() which triggers a plugin to run that writes the field value to a named range (1 cell) of an excel sheet.

However, I don't know which field caused the save. Is there a way to get that information? (Not all fields on the form need to go to the excel sheet)

If I use this: DynamicEntity target = (DynamicEntity)Context.InputParameters[ParameterName.Target]; I can look at specific fields, but I have no way of knowing which ones changed.

Any suggestions?

A: 

If your plugin is triggered on the Pre-Event of the Update on your entity, you should be able to compare the IPluginExecutionContext.PreEntityImages to your DynamicEntity that you've fetched from the Target.

Or if your plugin is triggered on the Post-Event of the Update, you should be able to compare the IPluginExecutionContext.PreEntityImages with IPluginExecutionContext.PostEntityImages.

Forgotten Semicolon
True, but it doesn't tell me which fields are my "certain" fields. In other words, I only care about certain fields changing.. and only when they change.
CraigF
A: 

It's my experience that only the changed fields will have value (in the DynamicEntity) when you update an entity. So let's say you have an entity with a FirstName and Lastname. If you only change the LastName and save. The LastName will have a value however FirstName with be null (unless you have som javascript code that forces the FirstName to be submitted).

Jeppe Vammen Kristensen
Right, which doesn't help because there may have been more fields changed in the meantime. So I am going to come at it another way. I'm going to build a webpage that runs in a CRM iframe and use jquery selectors to parse the page looking for the fields that I am interested in. Thanks for the effort!
CraigF
A: 

Looks like you are already going a different way, but another suggestion is to create a hidden field - "FieldThatChanged." In your field on-change javascript, set that field to the name of the field that changed, then access that in your plugin.

Josh Painter
A: 

Yep, totally changed the way I approached this. I'm using jquery in an iframe to pass all the exact fields (name/value pairs) I want to a method of an ASPX file running in the ISV folder that takes the neccesary action. Thanks for the suggestions all!

CraigF
A: 

I recommend using the Pre and Post Images as suggested by @Forgotten Semicolon. And in addition set the Filtering Attributes so the Plugin is triggered only on the change of the fields you care about.

shane carvalho