Answered by:
Plugin is not getting trigger on Associate message (for N:N relationship)

Question
-
Hi All,
I've a requirement to create a plugin on N:N relationship, for that I've created a plugin and registered it on Associate and Disassociate message, but my plugin is not getting trigger when I am adding records to the N:N relationship.
I'd register it on post stage as synchronous.
below is the plugin code which I am using.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using System;
using System.Data;
using System.Globalization;
using System.ServiceModel;
namespace TestPlugin
{
public class TestPlugin :IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
// IOrganizationService service = serviceFactory.CreateOrganizationService(null);
throw new Exception("Exception on Associate/Disassociate ");
}
}
}Can anybody tell me why this is not getting trigger? any help much appreciated.
Thanks!!!
Thursday, December 12, 2013 6:36 AM
Answers
-
are you talking about the addmember message for list entity?
I guess you should check the "message-entity support for plugins" excel file in the sdk
check this link as well http://msdn.microsoft.com/en-us/library/gg328561.aspx
Anubhav Bajpai
- Edited by Anubhav Bajpai Thursday, December 12, 2013 1:44 PM updated link
- Marked as answer by Manuj Gupta Friday, December 13, 2013 6:42 AM
Thursday, December 12, 2013 1:43 PM -
Hi Manuj,
I have tried the Plugin on associate message and it is working fine.. I have created a custom N:N relationship between Account and Contact and it is working fine. Hope you have registered step like given below.
Would you please confirm the entities on which you are performing this operation? If you are trying this between Marketing List and Account Or Contact than it would not fire. When we try to associate Marketing list and member there is separate message for that called: AddMember. You have to specify primary entity as List.
HTH!
If this post helps you, please click "Mark As Answer" on the post and "Vote as Helpful"
- Proposed as answer by Kalim Khan Thursday, December 12, 2013 4:48 PM
- Marked as answer by Manuj Gupta Friday, December 13, 2013 6:41 AM
Thursday, December 12, 2013 4:47 PM
All replies
-
Hi manuj,
Please try to register the plugin on Pre-Operation Stage.
Regards,
Prabhu G
Prabhu G
Thursday, December 12, 2013 6:54 AM -
Hi Prabhu,
Thanks for reply.
I'd already tested with Pre-operation stage but it is also not working. :(
Thanks !!!
Thursday, December 12, 2013 7:18 AM -
Hi Manju,
Did you register the plugin assembly and created the step using MS SDK Tool. Step needs to register as follows:
Message: Associate
PrimaryEntity: None (or do not specify)
Mode: synchronous
Event (Stage): Pre-ValidationAfter registering restart the async service as well.
The plugin fires for all the Entity, and you can check the Input parameters, see the following example, I have added system user sub-grid into account entity, and I want to do certain logic when ever a user gets added into this subgrid.
if (!context.InputParameters.Contains("Target")) return; var targetEntity = (EntityReference)context.InputParameters["Target"]; if (targetEntity.LogicalName != Account.EntityLogicalName) return; // only targeting Account entity. var rh = (Relationship)context.InputParameters["Relationship"]; if (rh.SchemaName != "syn_account_systemuser") return; // only targeting Account - User relationship
Hope this will help.Thomas
Thomas T(MCBMSS) If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
Thursday, December 12, 2013 8:16 AM -
Hi Manuj,
Don't see any issue here, just try to un-register and register it again, it should work in both post and pre.
Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.Thursday, December 12, 2013 8:18 AMModerator -
Hi Mahender & Thomas,
Thanks for your reply.
Thomas --> I am using the same steps to register this plugin which you are talking.
Mahender --> I tried this on both CRM 2011 and CRM 2013, in both case it is not working. any suggestion?
Thanks!!!
Thursday, December 12, 2013 9:06 AM -
Hi,
Can you first try to throw the error without any code being executed.
Change your exception code:
throw new Exception("Exception on Associate/Disassociate ");
to
throw new InvalidPluginExecutionException("Exception for Associate or Disassociate");
Moreover check your RegisterFile.crmregister file if it is updated to the correct message in the Visual Studio. You can refer to this blog for details.
Now before registering the plugin again:
1. delete the plugin steps and plugin in Customizations screen and publish the changes.
2. refresh your project in Visual studio and then deploy the changes.
I hope this helps to resolve your issue.
Anubhav Bajpai
- Edited by Anubhav Bajpai Thursday, December 12, 2013 9:45 AM update
Thursday, December 12, 2013 9:45 AM -
Hi Anubhav,
it's not working.. :(
I am trying this in both CRM 2011 and CRM 2013.
Thanks !!!
Thursday, December 12, 2013 10:09 AM -
Hello Manuj,
Can you please provide a screenshot of step from Plugin Registration Tool?
Dynamics CRM MVP/ Technical Evangelist at SlickData LLC
My blogThursday, December 12, 2013 10:58 AMModerator -
Hi Andrii,
Here is the screenshot of Step.
Thursday, December 12, 2013 11:32 AM -
This looks fine.
Are you sure that you've registered plugin on the same CRM Instance where you trying to add N-N relationship between entities?
Dynamics CRM MVP/ Technical Evangelist at SlickData LLC
My blogThursday, December 12, 2013 11:46 AMModerator -
yes.
I also tried this on two different CRM Instances. but the same result :(
Thursday, December 12, 2013 11:51 AM -
Manuj, Could you please explain your N:N relationship and what you were trying to do or what you were trying to achieve with the associate action?
Thomas T(MCBMSS) If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
Thursday, December 12, 2013 1:08 PM -
I am just using the system defined relationship for N:N relationship. I am using the N:N relationship between Marketing List and Account entity.
whenever I add any account to marketing list, I want to trigger this plugin.
Thursday, December 12, 2013 1:35 PM -
are you talking about the addmember message for list entity?
I guess you should check the "message-entity support for plugins" excel file in the sdk
check this link as well http://msdn.microsoft.com/en-us/library/gg328561.aspx
Anubhav Bajpai
- Edited by Anubhav Bajpai Thursday, December 12, 2013 1:44 PM updated link
- Marked as answer by Manuj Gupta Friday, December 13, 2013 6:42 AM
Thursday, December 12, 2013 1:43 PM -
Hi Anubhav,
This is the only one scenario , I want to trigger this plugin on associate/disassociate message.
Consider another scenario -- A custom N:N relationship between Account and Contact...
Thanks!!!
Thursday, December 12, 2013 2:04 PM -
Hi Manuj,
It seems strange, did you try plugin on other events and they are working as expected ??
Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.Thursday, December 12, 2013 3:53 PMModerator -
Hi Manuj,
I have tried the Plugin on associate message and it is working fine.. I have created a custom N:N relationship between Account and Contact and it is working fine. Hope you have registered step like given below.
Would you please confirm the entities on which you are performing this operation? If you are trying this between Marketing List and Account Or Contact than it would not fire. When we try to associate Marketing list and member there is separate message for that called: AddMember. You have to specify primary entity as List.
HTH!
If this post helps you, please click "Mark As Answer" on the post and "Vote as Helpful"
- Proposed as answer by Kalim Khan Thursday, December 12, 2013 4:48 PM
- Marked as answer by Manuj Gupta Friday, December 13, 2013 6:41 AM
Thursday, December 12, 2013 4:47 PM