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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Association using crm plugin registration tool

(0) ShareShare
ReportReport
Posted on by

I want to create a association step in plugin.

Kindly someone guide me how to do it

thanks in advance

*This post is locked for comments

I have the same question (0)
  • Nitesh Sharma Profile Picture
    on at
    RE: Association using crm plugin registration tool

    Hi,

    in this case how to identify that which entity comes in Entity1 and which entity comes in Entity2

    like I have User and Roles Entities which has N:N relationship and I want to register my plugin on associate message .. now if we associate one user record with one role record ... which entity ( User or Role) comes in Entity1 and which will be Entity2  ????

  • Suggested answer
    razdynamics Profile Picture
    17,308 User Group Leader on at
    RE: Association using crm plugin registration tool

    Hi Rajesh

    I believe you want to write a Plugin on Associate Message, In Plugins, the Associate & Disassociate messages behave little different than other messages. When you register a plugin on Associate message, you have to leave “Primary and Secondary” entities as ‘none’. Since we don’t provide entity names, the registered Plug-in step triggers on all “Associate” operations, so we have to check few conditions to let the “Association” trigger happen only between intended entities.

    You can use the below code template for Associate or Disassociate plugins

               EntityReference targetEntity = null;

               string relationshipName = string.Empty;

               EntityReferenceCollection relatedEntities = null;

               EntityReference relatedEntity = null;

               if (context.MessageName == “Associate”) {

                   // Get the “Relationship” Key from context

                   if (context.InputParameters.Contains(“Relationship”)) {

                       relationshipName = context.InputParameters[“Relationship”].ToString();

                   }                                    

                   // Check the “Relationship Name” with your intended one

                   if (relationshipName != “{YOUR RELATION NAME}”) {

                       return;

                   }

                   // Get Entity 1 reference from “Target” Key from context

                   if (context.InputParameters.Contains(“Target”) && context.InputParameters[“Target”] is EntityReference)  {

                       targetEntity = (EntityReference)context.InputParameters[“Target”];

                   }                      

                   // Get Entity 2 reference from ” RelatedEntities” Key from context

                   if (context.InputParameters.Contains(“RelatedEntities”) && context.InputParameters[“RelatedEntities”] is EntityReferenceCollection) {

                       relatedEntities = context.InputParameters[“RelatedEntities”] as EntityReferenceCollection;

                       relatedEntity = relatedEntities[0];

                   }

               }

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans