How to Make Custom Cascading Properties Without a Parental Relationship in Dynamics 365

Dominic Jarvis, 15 October 2017

When customising entities and their relationships in Microsoft Dynamics 365, there may be a time that you want to create a cascading relationship for an entity, to allow the cascading of properties such as ownership, or to delete child records when the parent record is deleted. This is most commonly achieved by using a parental or configurable cascading relationship. However, only one parental or cascading relationship can exist for any given entity.


If you’ve ever tried to make more than one before, you’ve probably encountered this:

image

This is commonly an issue when customising OOTB (out of the box) entities, as many of these have parental relationships pre-existing, for example:

  • Account => Account
  • Account => Appointment
  • Account => Case
  • Account => Contact
  • Account => Contract
  • etc.

Often, you may find that these relationships are either non-customisable, or that you want to maintain these relationships and their OOTB behaviours. You may even want to cascade values that you are not generally able to through use of a relationship, such as status, or status reason.
In these instances, it is a simple matter to cascade these properties using plugin(s). Let’s take status for example.

Example: Events, Registrations and Contacts

For the purposes of this example, I have two custom entities Event and Registration, with Registration acting as an intersect between the Event entity and the Contact entity (records number of tickets, purchase date, etc.).
For the purposes of this example, let’s assume that I have been given a requirement that when the status of an Event changes, all child Registrations should also have their status be changed.
This is very simple, and can be performed in two steps.

Get Child Records

The first step is to get the child records of the entity being deactivated – in this case, an Event entity. This can be accomplished via a quick RetrieveMultiple, filtering on the id of the Event entity.


clip_image002[4]
 

Perform Action on Child Records

The next step is to perform the desired action on all child records. This is again a very simple process, and can be achieved by looping through the child records and performing the required operation on each.


clip_image002[6]

Common Uses

Common uses of this type of plugin are cascading properties of an entity that are usually cascaded via parental relationships, such as Assign and Delete, or to cascade other properties that are not usually configurable via relationships, such as status, custom fields – e.g. I may want to update the related Registration if the cost of the Event changes.

SDK Messages

There is one small thing that you have to watch out for here. In most cases, these plugins can be registered pre-operation (sync) or post-operation (sync or async), but in the case of delete, this plugin must be registered pre-validation, as when the process gets to the pre-operation stage, entity has already been removed from all lookups, so the Get Child Records query will not return anything.