Skip to main content

Dynamics 365 CRM Entity Relationships and Behaviour

Entity relationship defines how a specific entity record is related to another entity record. In this post we will discuss what is entity relations and details about this topic. We will learn below points in this article,
  • Fundamentals of entity relationship
  • Relationship V/s Connections
  • Types of Entity Relationships
  • Relationship Behaviors
  • How to create Relationships

Fundamentals of Entity Relationship

Entity relationships define how records can be related to each other in the database. When you are adding a lookup field to an entity the system creates a new 1:N (one-to-many) relationship between the two entities and lets you put that lookup field in a form. Using lookup field you can associate an entity record with another entity record.

Relationship V/s Connections

Although these two word looks like similar we have to understand when to use connections and when to use Relationships. The below grid speaks about it.
RelationshipsConnections
1.    This is a formal relationship between entities1.    This is less formal relationship betwwen entities
2.    We can configure Relationship behaviors using Entity Relationship2.    We can configure Connection Role in connections creation.
3.    E.g. : An opportunity without a customer is not accepted so we have an entity relationship between Opportunity and Contact so that we can query and report data efficiently.3.    E.g.: If one contact is spouse of another contact, or one contact is an employer of another contact, so for such type of relationship we define Connections.
4.    Relationships are defined as 1:N, N:N with additional relationship behavior.4.    Two entity records are connected by a connection Role such as , Employer, Spouse etc.

Types of Entity Relationship

There are two types of Relationships while customizing entities using relationships. They are given below.
  • 1:N (One-to-Many)
An entity relationship where one entity record for the Primary Entity can be associated to many other Related Entity records because of a lookup field on the related entity.
When viewing a primary entity record you can see a list of the related entity records that are associated with it.
  • N:N (Many-to-Many)
An entity relationship that depends on a special Relationship Entity, sometimes called an Intersect entity, so that many records of one entity can be related to many records of another entity.
When viewing records of either entity in a N:N relationship you can see a list of any records of the other entity that are related to it.

Relationship Behavior

When a one-to-many entity relationship exists there are cascading behaviors that can be configured to preserve data integrity and automate business processes. This topic will explain some key concepts and describe how you can configure these cascading behaviors.
We have 4 types of relationship behavior as given below.
  1. Parental
In a parental relationship between two entities, any action taken on a record of the parent entity is also taken on any child entity records that are related to the parent entity record. if you delete a record in the parent entity, the related child entity records are also deleted; or if you share a parent entity record, the related records from the child entity are also shared. All option are disable for Parental relationship.
  1. Referential
In a referential relationship between two entities, you can navigate to any related records, but actions taken on one will not affect the other
  1. Referential, Restrict Delete
Actions taken on parent will not affect child record but parent record cannot be deleted till the child record exists. i.e you cannot delete a record when related records exist.
  1. Configurable Cascading
You need to specify your setting here.
We can set the cascading behavior for the operations like, Assign, Share, Unshare,Reparent,Delete & Merge. We can have one of the below cascading options while configuring relationship.
The type we are interested here is “Configurable Cascading”. It allows you to decide what type of behavior we need to apply.The useful details of different cascading rules are (note here me is referred to the user on whom you will perform actions)
• Cascade All: Perform action on all of my child records. Like if assigned my account to another user then all my activities, orders, invoices etc are assign to new user including open, completed and other user owned records
• Cascade Active: Perform action on only my active child records
• Cascade User-Owned: Perform action on all my child records which is owned by me
• Cascade None: do nothing to my child records
• Remove Link: remove link from child record
• Restrict: Applies to Delete. The delete is not allowed if there are other entity instances that reference the ID of the entity instance being deleted.
As per Microsoft the definitions of the cascading concept is given below.
The below matrix is specifies the default relationship behavior cascading concept. In the below matrix wherever we have “cannot be changed” means we can not select to choose other option the value is pre-populated by system and can not be changed.This means for example if the behavior is parental then if we assign a record to a new user then all the child entity records will also be assigned to the user automatically due to “Cascade All” behavior.

How to create Relationship

In this section we will understand how we can create a relationship behavior for a 1:N relationship type.
Step-1: Open Dynamics 365 -> Goto Settings Area -> Select Customization->Open Customize the System
Step-2: In the default solution ->Expand the Entity option and select the entity to add relationship
Step-3: In entity -> Select 1: N relationship and add new relationship a sample snapshot given below.
 Step-4: Choose the mandatory fields and also the cascading behaviors.
Step-5: Now save it and check a lookup field in referencing entity.

Comments

Popular posts from this blog

Microsoft Dynamics 365 CRM Troubleshooting Solution Import Errors

Remember when CRM life was so much simpler that solutions did not yet exist? If you had separate development and production environments and you wanted to move your customizations, you simply clicked  Export Customizations  and voila! It was done. Those were the days. Nostalgia Warning – in case you’ve forgotten, here’s a screenshot to jog your memory: With CRM 2011, the concept of solutions was introduced, giving us a new set of powers – by picking individual entities, workflows, etc., we now had the ability to group together and move only those customizations we wanted to include in our solution. The next great solutions advancement came with CRM 2016: we can now select specific components within each individual entity – so instead of moving the entire contact entity, for example, we have the option of moving only a certain view or field within the entity. And we can do this without having to hack the xml in the zip file. (By the way, if you want to learn more abou...

How to Filter SubGrid Lookup view in Dynamics 365 CRM

How to Filter SubGrid Lookup view in Dynamics 365 CRM.  Please check the comments in the below code and do follow the steps accordingly and call the  filterSubGrid() funtion on onload. var LastQuery = ""; function filterSubGrid() { debugger; setSubgridLookupFiltering(); } function AddLookupFilter(entity_type, customFilter) { var subgridLookup = Xrm.Page.getControl("lookup_Contacts_Participants"); subgridLookup.addCustomFilter(customFilter, entity_type); } function setSubgridLookupFiltering() { var subgridAddButtonId = "Contacts_Participants_addImageButton"; //Try to get the element from both the current and the parent document. var subgridAddButton = document.getElementById(subgridAddButtonId) || window.parent.document.getElementById(subgridAddButtonId); //This script may run before the subgrid has been fully loaded on the form. If this is the case, //delay and retry until the subgrid has been loaded. if (subg...

How to prevent record from saving in Dynamics CRM using Javascript

  From time to time you might need to add some validation to the save event of an entity, this actually used to be an approach I would use on a regular basis but since the introduction of business rules have found myself doing this less and less. But still, knowing the ability is available is handy. When you define the onsave event function, you must tick the “Pass execution contact as first parameter” option. (See below) Having done that you can create an onSave function with code similar to the example I have shown below. Note forgetting the “(context)”, which will take the context parameter allowing you to prevent the save when needed. function onSave(context) { var saveEvent = context.getEventArgs(); if (Xrm.Page.getAttribute("telephone1").getValue() == null) { // *** Note: I am using an alert for testing a notification maybe better! alert("Put in a phone number!"); saveEvent.preventDefault(); } } Note: This simple example might be better achi...