Reputation: 1469
In crm i have solution with several entities. There are three that are causing a problem. Lets call them A, B and C.
A and B have a one to many relation with a cascading effect on deletion
B and C have a one to many relation without a cascading delete.
for B i have developed a crm plugin that, when deleted, it removes C as well. A sort of cascading delete plugin. I cannot create a cascading between B and C, since C is already in a cascading relationship with another entity.
When i delete any entity B, it fires off plugin code and deletes all children of C. When i delete any entity A, it cascade deletes B, but it does not fire off the plugin.
How can i ensure that the plugin does fire, without creating a plugin for entity A? I am fairly new at crm so i don't really know where to look for this kind of problem.
UPDATE
The plugin used to fire at the 'Pre-validation' stage. Changing it to 'Pre-operation' actually caused the plugin to fire. Unfortunately at this stage all Child references of the object where already removed. So now when A is deleted B is cascade deleted, and the plugin fires, but i cannot find any of it's child entity C references
Upvotes: 2
Views: 679
Reputation: 3105
During cascade delete, only the triggering entity's PreValidation
will be called.
For your entity B
this means that this stage will be skipped.
As Joseph noted, setting a shared variable in PreValidation
can generally be used to have information about already deleted data available in PreOperation
, but you would have to ensure that this shared variable is set also when deleting A
.
In case any of your entities are solution aware, deleting the solution with these records will also trigger a cascade delete, whereby PreValidation
is only called on the solution
entity.
Henk's suggestion is feasible, if the set of C
records related to B
do not need any kind of processing, like sorting.
Upvotes: 1
Reputation: 795
Create an object which will store the child references and pass it into the "Shared Variables" in the Pre-Validation stage. Then you can access the shared variables in the pre-operation stage: https://msdn.microsoft.com/en-us/library/gg328579.aspx. You will need plugins registered at both steps, but this will handle both of your challenges.
Upvotes: 0