TUTORIAL: Adding Relationships to an Entity

This is a tutorial on adding relationships to an entity. In MSCRM relationships allow us to link entities together. A good example is accounts and contacts. An account has a relationship with contact that dictates that an account has many contacts. Adding relationships between entities allows us to better model our client’s business processes. We also get other benefits from using relationships such as data mapping and better reports. Another benefit is if we choose the right relationship it helps reduce duplicated records.

Quick Tip

Quick Tip

If you find yourself designing an entity and adding replicated fields on to it. EG new_name1, new_name2, and new_name3, the chances are you have the start of a new entity and a relationship to it.

In MSCRM there are 3 types of relationships you can create which are as follows.

  • One to Many – EG an account can have many contacts.
  • Many to One – EG many contacts can belong to an account.
  • Many to Many – EG many contacts can belong to an account and an account can have many contacts.
Quick Tip

Quick Tip

You should try to avoid using a many to many relationship. A many to many relationship has a few limitations when it comes to further extension through plugins. If you need a many to many relationship create a new entity that sits between your two entities that allows you to link up as a one to many and many to one.

Create a Relationship

    • Navigate to your solution or base customisation.
    • Select Entities from the solution tree.
    • Expand your starting entity.
    • Select the relevant relationship your require. 1:N, N:1 or N:N and click New.
    • Now select your related entity.
    • If you have selected 1:N or N:1 you will be able to create the lookup field and set the navigation panel label. These two labels are basically your end points of your relationship. The navigation panel allows you to configure the label for the many side of things. The lookup allows you to set the label for the single side of things. By default the navigation panel will show the plural name of the entity, you can however use a custom label if you so wish. If you have created a many to many relationship you will not have a lookup field created. You will instead have two navigation labels to set.
      Relationships
      1:N Account to Contact Relationship
    • Save the relationship you have created and publish. At this point the relationship is created.
Information

Relationship Behaviour

It is posible to configure how the relationship between your entities behave. Relationship Behaviours always determines how an action on the parent effects the child. For example if I was to delete the parent should all the children be deleted aswell? There are 3 types of predifined behaviours plus an option to manually configure the relationship behaviour.

  • Parental – A child can only have one parental reference. With a parental reference every action on the parent is cascaded down to the child.
  • Referential – Nothing is cascaded down from the parent to the child. When deleting the parent the link between the parent and the child is removed, but the child record is not deleted.
  • Referential, Restrict Delete – Nothing is cascaded down from the parent to the child. If the parent has children CRM will stop you from deleting the parent.
  • Configurable Cascading – Allows you to manually alter how cascading is configured for, asigning, sharing, unsharing, deleting, reparenting, and merging.

When you start to get a feel for relationships it is definitely worth revisiting relationship behaviours to see if you can tidy up your cascading for your clients needs.

Quick Tip

Quick Tip

To help understand the direction of the relationship always read your current entity as the node on the left. For example if I’m on account for 1:N it would read One Account has Many XXXXX

You can perform further customisations to tidy things up. EG add the lookup field that was created to the related form, or order the label in the navigation panel. You can also create mappings that copy fields from one side of the relationship to the other.

Quick Tip

Quick Tip

You can completely hide a relationship from the browsing client. This is great for entities that exist only for population by automation. Hiding the relationship helps keep the CRM system tidy. To hide the relationship do not place the lookup on to the form at the many side of the relationship. Also at the single side of the relationship you should change the display option to do not display.

Leave a Reply

Your email address will not be published. Required fields are marked *