locked
CRM 2011 Bug: Plugin Delete Message RRS feed

  • Question

  • I'm pretty sure I've identified a problem with the CRM pre-operation delete process.  I've registered a plugin in the pre-operation pipeline to delete an N:1 relationship record with the entity I'm deleting.  The particular record I'm trying to delete in the plugin is an invoice that is setup with a referential relationship.  The problem is the relationship link is removed before this pre-operation plugin so I can't get access to the invoice in order to delete it.  I found the following article which says to use the pre-validation plugin:  http://mscrmrandomthoughts.wordpress.com/2011/01/05/plugin-on-delete-message-not-working-in-crm-2011/.  This works great except when the record is deleted in the child pipeline (cascade delete), the plugin does not get triggered. CRM 2011 has moved the child pipeline but apparently the pre-validation does not get triggered during the old child-pipeline from 4.0.
    Wednesday, May 11, 2011 4:12 PM

Answers

  • Try registering on Pre-validation. That will work.

    Thursday, May 12, 2011 8:23 AM
  • It worked.

    To clarify, in case the link breaks:

    Delete passes an EntityReference instead of an Entity so none of the code samples that you will see will work without the minor modification.

    I used the following as my Plugin is running for multiple messages:

    if

    (context.InputParameters.Contains("Target") && (context.InputParameters["Target"] is Entity || context.InputParameters["Target"] is EntityReference))

    Then you just need to handle the difference between Entity and EntityReference in your code.

    I was able to get the Plugin working for both Pre-Validation and also Pre-Operation without a problem.

    Thursday, December 8, 2011 10:50 AM

All replies

  • Hello -

    Since the link is being broken before your plugin executes, try registering your plugin on the "disassociate" message.

    -Brandon

    Wednesday, May 11, 2011 6:11 PM
  • Brandon, the issue is I'm trying to delete related records in the plugin.  I'm basically doing a cascade delete from invoice to other related records within the plugin.  I don't think I want to execute this logic in a "disassociate" message.
    Wednesday, May 11, 2011 6:34 PM
  • Try registering on Pre-validation. That will work.

    Thursday, May 12, 2011 8:23 AM
  • Jan AS, did you read the post?  The pre-validation plugin doesn't get triggered when the process is deleted in the child-pipeline.  You can duplicate it by the following:

    Entity A has a 1:N relationship with Entity B.  Set the relationship to cascade delete.  When you delete Entity A it cascade deletes all Entity B child records.  If you have a pre-validation delete plugin on Entity B, it does not get triggered.

    Thursday, May 12, 2011 2:22 PM
  • Was there a solution to this?  I am having the same problem.

    I have a Plugin which runs on Create, Update and Delete.  I cannot get the Delete to fire at all.  Tried pre-op and pre-val to no avail.  Both Create and Update are fine.

    Like you, I am removing a child from a sub-list.  I am using a single plugin for all three Message types so it is possible that the Delete Plugin is so different in nature that is doesn't run because I am filtering out the event somehow.  I am sure that I'm not doing anything in code to prevent the Delete from at least running.

    With Disassociate, I though that was for Many-to-Many relationships.  In any case, I am Deleting the child record so it doesn't seem to make sense to try and use Disassociate which implies that the record still exists after the action.

    Any tips or a checklist would be useful for developers who find this post.

    Thursday, December 8, 2011 10:21 AM
  • It worked.

    To clarify, in case the link breaks:

    Delete passes an EntityReference instead of an Entity so none of the code samples that you will see will work without the minor modification.

    I used the following as my Plugin is running for multiple messages:

    if

    (context.InputParameters.Contains("Target") && (context.InputParameters["Target"] is Entity || context.InputParameters["Target"] is EntityReference))

    Then you just need to handle the difference between Entity and EntityReference in your code.

    I was able to get the Plugin working for both Pre-Validation and also Pre-Operation without a problem.

    Thursday, December 8, 2011 10:50 AM