Advertisements

Archive

Posts Tagged ‘Relationship’

D365/CRM – Document Template – Missing entity relationship

Other day, I was configuring a ‘Document Template’ for a custom entity (Acknowledgement) which has a 1:N Relationship with Contact entity.

DocTemp_1

For some reason, the Relationship was not showing up in the ‘1:N Relationship’ grid of the ‘Document Template’ configuration screen.

DocTemp_2

Reason & Fix:

  • The relationship ‘Searchable’ field was set to ‘No’ and hence it was not showing in the list.
  • Set the ‘Searchable’ field to ‘Yes’ and publish.

DocTemp_3

  • Refresh the Document Template’s ‘1:N Relationship’ grid and you should see the relationship now.

DocTemp_4

🙂

Advertisements
Categories: CRM Tags: ,

Associate/Disassociate plugin messages in CRM

April 17, 2013 11 comments

In CRM, the Associate or Disassociate event happens

  • If you have a N:N relationship between two entities and when you try to associate or disassociate records either from Associated view or Sub grid.
Entity Associate View

Entity Associate View

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’.
Associate Plugin Step

Associate Plugin Step

  • 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];

                }

            }

🙂