Dynamics CRM Entity Relationship Behavior Explained

Let’s talk about Dynamics CRM Entity Relationship behavior! There are several behaviors in Dynamics CRM that we can apply to fit our requirements. With this blog post, I hope we can learn together about those options. 

Create a lookup will automatically create a relationship

But first, we need to understand the entity relationship. When we link (create a lookup) from one entity to another entity, by default CRM will create an entity-relationship (1-to-N, N-to-1, or N-to-N). We can specify from simple behavior how the changes on the parent will affect the children such as referentialparental, and some advanced behaviors to handling: deletionassigningsharing-unsharing, and reparent.

Referential Behavior

On Referential, we can set Delete behavior as Remove Link/Restrict

By default, when we create a lookup, CRM will set the behavior as Type of behavior: Referential and Delete: Remove Link. When the deletion happens to the parent, the children will not be deleted and only will set lookup as empty (null).

When Parent 1 deleted, the children’s lookup will be set as null

When we set the behavior as Type of behavior: Referential and Delete: Restrict. When the deletion happens to the parent and the record got children, it will throw an error “The record cannot be deleted because it is associated with another record.“.

When set as restrict delete, parent can’t be deleted if still have associated record(s).

Parental Behavior

Set the behavior parental.

When we set the behavior as Type of behavior: Parental and when The parent record is deleted, it will delete the Children records.

Custom Behavior

Custom Behavior UI

In the custom behavior, we can specify specific behavior in 5 actions:

1) Delete

Delete options
  • Cascade All > when the parent record is deleted, all the children will be deleted as well.
  • Remove Link > when the parent record is deleted, all the children’s lookup will be set as null.
  • Restrict > the deletion of the parent will be blocked if the record having children record.

2) Assign

Assign action. Remember the target user/team must have the same/higher security role to be able use this action.

An action to change the ownership of the record to another user/team. You can learn more about this action in the AssignRequest message. Meaning in this action, when the parent record is assigned to another user/team, the children’s records will be assign also.

  • Cascade All > when the parent record is assigned to another user/team, all the children will be assigned also.
  • Cascade Active > only the children records that the status is active will be assigned.
  • Cascade User-Owned > only the children records which own by the user will be assigned.
  • Cascade None > no children will be assigned if the parent is assigned to another user/team.

3) Share/Unshare

Share (tick) or Unshare (untick) the record to another user/team

An action to give access to the record to another user/team. You can learn more about this action in this documentation if you want to do it programmatically.  Share action will give them access to the record using the GrantAccessRequest message. While to unshare, you can use the RevokeAccessRequest message.

  • Cascade All > when the parent record is shared with another user/team, all the children will be shared also.
  • Cascade Active > only the children records that the status is active will be shared.
  • Cascade User-Owned > only the children records which own by the user will be shared.
  • Cascade None > no children will be shared if the parent is shared with another user/team.

4) Reparent

An action when we set a lookup (when on create or update message). There is a blog post from the crmtipoftheday that you can check to learn more about this.

  • Cascade All > when the value of the lookup record is switched with another record, all the children can be accessible.
  • Cascade Active > only the children records that the status is active will be accessible.
  • Cascade User-Owned > only the children records which own by the user will be accessible.
  • Cascade None > no children will be accessible if the reparent occurred.

Conclusion?

You must at least understand about what the behavior that we can apply when we create a lookup. Not just relying on the default behavior, we can apply this knowledge to achieve simplicity in our application depends on your requirement of course!

Advertisement

One thought on “Dynamics CRM Entity Relationship Behavior Explained

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.