Answered by:
Crm 2011 -- Delete message plug-in not firing

Question
-
I have a custom entity with a plugin.
I have registered a step for the delete message, but it does not trigger.(the plugin also has a step for update and this one triggers fine).
There are no errors on the logs. The entities are deleted just fine, but the plugin has not been run
Any ideas?
TIA
edit:
I have change the step so that it would trigger when deleting a role, but it still did not trigger. So obviously not related to custom entities
- Edited by a1pro Friday, March 4, 2011 2:26 PM extra info
Friday, March 4, 2011 2:19 PM
Answers
-
If you are using the same plugin for both Update and Delete you might have a line that checks if the "context.InputParameters["Target"] is Entity". If so then this explains why the Update works and the Delete does not. When the Delete message is triggered the context.InputParameters["Target"] is of type EntityReference and not Entity. What might be happening is that it is just exiting the IF statement.
Best option to you create a seperate class for the Delete plugin.
void IPlugin.Execute(IServiceProvider serviceProvider) { // Obtain the execution context from the service provider. Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext) serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext)); // Obtain the organization service reference. IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); // The InputParameters collection contains all the data passed in the message request. if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference) { EntityReference entityRef = (EntityReference)context.InputParameters["Target"]; // YOUR CODE HERE } }
- Marked as answer by a1pro Friday, March 4, 2011 3:19 PM
Friday, March 4, 2011 2:43 PM
All replies
-
Try re-registering the plugin on pre-validation
Here is what I found:
It worked for someone else at this thread:
http://social.microsoft.com/Forums/eu/crm2011beta/thread/f6cb2081-eb21-4df7-86bc-5d41f2aa8b27
Jamie MileyFriday, March 4, 2011 2:41 PMModerator -
Is it possible that you try to use a guid that is already deleted when you enter the plugin. Try to run it before the transaction.Friday, March 4, 2011 2:41 PM
-
If you are using the same plugin for both Update and Delete you might have a line that checks if the "context.InputParameters["Target"] is Entity". If so then this explains why the Update works and the Delete does not. When the Delete message is triggered the context.InputParameters["Target"] is of type EntityReference and not Entity. What might be happening is that it is just exiting the IF statement.
Best option to you create a seperate class for the Delete plugin.
void IPlugin.Execute(IServiceProvider serviceProvider) { // Obtain the execution context from the service provider. Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext) serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext)); // Obtain the organization service reference. IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); // The InputParameters collection contains all the data passed in the message request. if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference) { EntityReference entityRef = (EntityReference)context.InputParameters["Target"]; // YOUR CODE HERE } }
- Marked as answer by a1pro Friday, March 4, 2011 3:19 PM
Friday, March 4, 2011 2:43 PM -
I'd seen the first of your links and I should have mentioned that I have tried registering them at each step (pre-val, pre-oper and post-oper (crm 2011)), but it won't trigger.
I'll try setting verbose tracing on and see if something crops up.
Friday, March 4, 2011 2:58 PM -
Thanks for this.
I had my breakpoint further down the plugin, explaining why it did not go into the plugin code.
My trace with verbose revealed that it was running, which it was. D'oh!!!
At any rate, thanks
Friday, March 4, 2011 3:20 PM -
Hi,
Best option to you create a seperate class for the Delete plugin.
void IPlugin.Execute(IServiceProvider serviceProvider) { // Obtain the execution context from the service provider. Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext) serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext)); // Obtain the organization service reference. IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); // The InputParameters collection contains all the data passed in the message request. if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference) { EntityReference entityRef = (EntityReference)context.InputParameters["Target"]; // YOUR CODE HERE } }
Tuesday, March 19, 2013 1:17 PM