web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Does IOrganizationService.(Dis)Associate not trigger (Dis)Associate plugins?

(0) ShareShare
ReportReport
Posted on by 15

Hello,

I have two entities, Events and Missions that have a N:N relationship. I registered a plugin (let's call it NewPlugin) to run on both associate and disassociate between these two entities. NewPlugin works just fine when a user manually associates a Mission to an Event via a subgrid, and same when disassociating.

The issue is that we also have OldPlugin that, among other things, can potentially associate several Missions to an Event at once via the IOrganizationService.Associate method. Unfortunately, the associations made via OldPlugin don't appear to trigger NewPlugin at all. I have some tracing in NewPlugin, but I'm not seeing any trace logs being created after OldPlugin runs, which tells me that NewPlugin doesn't get triggered at all.

Is this an instance of Microsoft half-assing their implementation of the (dis)associate messages/plugins, or am I doing something stupid? Would I be better off swapping my plugin to run on an Event's update instead?

Note: we're running version 1612 (9.0.32.3) on-premises if it helps. 

I have the same question (0)
  • Ahmed Al-Khatib Profile Picture
    5 on at

    Hello,

    If you wanted Newplugin to trigger after Oldplugin , then set the execution order of your Newplugin to 2. If not , then vise versa.

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hello,

    I have just tried in my online instance and it works as expected.

    I have register plugin steps for Associate & Disassociate as below-

    CR1.JPG

    I have used below code from C# to associate & disassociate records-

     public static void AssignSecurityRole(Guid guidSystemUserId, Guid guidSecurityRoleId, IOrganizationService crmService)
            {
                
                // Create new Associate Request object for creating a N:N relationsip between User and Security
                AssociateRequest objAssociateRequest = new AssociateRequest();
                // Create related entity reference object for associating relationship
                // In this case we SystemUser entity reference  
                objAssociateRequest.RelatedEntities = new EntityReferenceCollection();
                objAssociateRequest.RelatedEntities.Add(new EntityReference("systemuser", guidSystemUserId));
                // Create new Relationship object for System User & Security Role entity schema and assigning it 
                // to request relationship property
                objAssociateRequest.Relationship = new Relationship("systemuserroles_association");
                // Create target entity reference object for associating relationship
                objAssociateRequest.Target = new EntityReference("role", guidSecurityRoleId);
                // Passing AssosiateRequest object to Crm Service Execute method for assigning Security Role to User
                crmService.Execute(objAssociateRequest);
            }
    
            public static void RemoveSecurityRole(Guid guidSystemUserId, Guid guidSecurityRoleId, IOrganizationService crmService)
            {
    
                // Create new Associate Request object for creating a N:N relationsip between User and Security
                DisassociateRequest objAssociateRequest = new DisassociateRequest();
                // Create related entity reference object for associating relationship
                // In this case we SystemUser entity reference  
                objAssociateRequest.RelatedEntities = new EntityReferenceCollection();
                objAssociateRequest.RelatedEntities.Add(new EntityReference("systemuser", guidSystemUserId));
                // Create new Relationship object for System User & Security Role entity schema and assigning it 
                // to request relationship property
                objAssociateRequest.Relationship = new Relationship("systemuserroles_association");
                // Create target entity reference object for associating relationship
                objAssociateRequest.Target = new EntityReference("role", guidSecurityRoleId);
                // Passing AssosiateRequest object to Crm Service Execute method for assigning Security Role to User
                crmService.Execute(objAssociateRequest);
            }

    See below image for plugin trace logs-

    CR62.PNG

    I don't have access to On-premise instance. I would recommend to verify these things to check if all setup is correct on your instance.

    If it still does not work, I would ask you to lodge Microsoft support ticket.

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 61

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans