Skip to main content

Notifications

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. 

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Does IOrganizationService.(Dis)Associate not trigger (Dis)Associate plugins?

    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/

  • Ahmed Al-Khatib Profile Picture
    Ahmed Al-Khatib 5 on at
    RE: Does IOrganizationService.(Dis)Associate not trigger (Dis)Associate plugins?

    Hello,

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

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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans