There are three different types of relationships within Microsoft Dynamics 365/CRM: 1-to-many (1:N) relationships, many-to-1 (N:1) relationships, and many-to-many (N:N) relationships.
1-to-many, or 1:N relationships, are used when you are creating a relationship between two entities where there are multiple records from one entity associated with a single record from another entity.
In layman’s terms, this means when you have a parent (or primary) entity and many related (or child) entities.
The classic example of a 1-to-many (1:N) relationship is between Account (1) and Contact (N). You can have one Account with many Contacts who are associated with it.
By default, each Contact record has a lookup field back to an Account record. So, each Contact can be set to one Account record. Then, when looking at an Account record, by default there is a sub-grid of the many Contacts that are related back to the Account.
Common 1:N relationships are:
- Accounts to:
Now, 1:N relationships can also be applied to custom entities. A common example we see is around managing Projects and their related items within D365.
A custom entity called Project (1) is created and then another entity called Project Items is created (N).
A 1:N Relationship is built between Project and Project Items so a User can manage all the items associated to a Project.
The many-to-one (N:1) relationship is just a looking at the N:1 relationship in reverse. So, in going back to our Account to Contact 1:N relationship example, the N:1 relationship is Contact to Account.
When looking at the relationships under an entity, looking at the 1:N listing will show you all the entities that are classified as parents.
If you look at the N:1 listing, it will show you all the entities that are classified as children. Now you will see entities (like Accounts) that are in both listings, this just means they are a parent to some entities and children to others – this is more advanced and could be a future topic if requested.
To create or edit a 1:N relationship between entities, follow these steps:
- Open solution explorer
- Under Components, click on “Entities”, then expand the Entity you want to work with
- Select 1:N Relationships
- If you want to edit an existing Relationship, click on the relationship, then on the Actions toolbar. To edit, select “More Actions”, then “Edit”. To add a new relationship, click on “New 1-to Many Relationship”.
- For new relationships, you will want to select the related entity. To do this, navigate to the Relationship Definition section, and choose from the Related Entity list to select which you’d like to be related to your new relationship.
- Choose whether or not you want this to be searchable before continuing on.
- Define a value for the “Display Name” field in the “Lookup FIeld” section.
- Specify data requirements for the field before you save by selecting an option in the Field Requirements list.
- Choose an option for displaying associated views or a custom label via the Navigation Pane Item for Primary Entity section, and using the Display Option list.
- In the “Relationship Behavior” section, choose from the following options in the “Type of Behavior” list:
- Referential, Restrict Delete
- Configurable Cascading
(Note: Learn more about these behaviors by watching the user group webinar referenced below.)
- Click “Save and Close” once you’re done to close out the Relationship form.
- When you’ve completed your customizations, publish them.
Learn more about 1:N Relationships when you replay Ledgeview’s Dec. 2018 Microsoft Dynamics 365/CRM User Group Webinar, “Best Practices for the Advanced Admin”.
Want more technical tips and insight like this from the experts at Ledgeview? Sign up for the next user group webinar here.