0

I'm deleting an instance of an entity and depending on the value of an option set in it, I wish to carry our different course of action. The problem is that the field isn't changed, hence, not provided to the plugin's target.

How can I easily tell the stupid plugin to fetch all the fields?

The way I do it now is to use pre-image but I'll be showing the plugin to some rookies and they will definitely not like it. And they won't believe me that's the way to go, for sure, because they're a cocky bunch.

Is there a work-around for that?

Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
  • Why won't they like the pre-image approach? It is the most straightforward. – BlueSam May 17 '15 at 17:18
  • 1
    @BlueSam One would think so. But I got one guy who's really following y advice **but** a bunch of others who, well... They prefer to find their own ways. And using a pre-image (and post-image) constitutes a work overhead, which **will** cause them to whine and request that I show them a way "*appropriate for beginners*". I really wish I could suggest them an other employer but, unfortunately, at the moment I lack the power of booting people who don't feel like working. – Konrad Viltersten May 17 '15 at 20:08
  • It is part of the `IPluginExecutionContext` (of which `Target` is one part.) I think the beginners are confused if they think of `Target` as anything more than a property of `IPluginExecutionContext`. It wouldn't make sense to have these values as part of `Target`, b/c then it would cause an update of the field to its current value - if you forced it into `Target` you would see the update in the audit details. So we have `PreEntityImages`, `Target`, and `PostEntityImages`...if `Target` was used the way "they" want it, how would it also handle `PostEntityImages'? It couldn't. – Nicknow May 19 '15 at 03:57
  • 1
    @Nicknow That was one heck of a well stated explanation. Why don't you put is as a reply so I can sprinkle some reputation on your user, please. – Konrad Viltersten May 19 '15 at 10:25

2 Answers2

2

Using the pre-image is the suggested way in this scenario, the alternative is to instantiate a service factory in order to get an IOrganizationService and retrieve the entity using the target's Id.

Guido Preite
  • 14,905
  • 4
  • 36
  • 65
1

It is part of the IPluginExecutionContext (of which Target is one part.) I think the beginners are confused if they think of Target as anything more than a property of IPluginExecutionContext.

It wouldn't make sense to have these values as part of Target, because then it would cause an update of the field to its current value - if you forced it into Target you would see the update in the audit details.

Thus, CRM has PreEntityImages, Target, and PostEntityImages, if Target was used the way "they" want it would not be able to differentiate between values being updated, previous values, and the final result of the entity.

Nicknow
  • 7,154
  • 3
  • 22
  • 38