This information pertains to Microsoft Dynamics CRM 2015 and later versions.

The Microsoft Dynamics CRM 2015 update introduced the capability to define specific self-referencing one-to-many entity relationships as hierarchical.

Previously in CRM 2013 and prior versions, you were able to create hierarchies of related records using self-referential relationships, but you had to iteratively query for the related records. New capabilities in CRM 2015 let you query and view the records as hierarchies.

About Hierarchical Data

Hierarchical data is nested (self-referencing) data where each record is known as a node. The data becomes hierarchical when a node contains child nodes, and those can contain child nodes, and so on. A node that doesn’t have any children is known as a leaf.

Examples of Hierarchical Data

  • An enterprise's organizational chart; employee reporting structures
  • File folders
  • Categories
  • Genealogy tree
  • Sections, such as at a stadium
  • Business units, company branches

This example of a simple (and admittedly silly) data hierarchy shows which circus clown is the boss clown of other clowns. Four clowns report to Snuggles and Snuggles reports to Mister Sniffles.
wiki_crm_hierarchical_example1.png

Hierarchical Data Support in Dynamics CRM 2015

  • Each entity can have just one self-referential one-to-many entity relationship that is considered hierarchical. This declaration is included in the metadata of the relationship.
  • No child entity may have more than one parent entity

To query an entity as a hierarchy you must enable a One-to-Many (1:N) or Many-to-One (N:1) self-referential relationship as hierarchical. You’ll be able to query records using Under and Not Under logic. The Under and Not Under hierarchical operators are exposed through Advanced Find and the workflow editor. For more information on how to use these operators, see Configure workflow steps.

You can gain valuable business insights by visualizing hierarchically related data. The new visualization feature gives you a hierarchical view into the data. You’ll be able to enable visuals for specific system entities and custom entities after you have updated the hierarchy settings for the entity. Users can choose between a tree view, which shows the entire hierarchy, and a tile view, which is a detailed view of a smaller portion of the hierarchy. You can explore a hierarchy by expanding and contracting a hierarchy tree. Also, you can compare the attributes between the records at multiple levels in a tree and perform actions on one or more records right from the tree view. Once defined, the hierarchy settings enable visualization in the CRM web application and in Microsoft Dynamics CRM for tablets, but, for the tablets, in a modified format suitable for the smaller form factor. Because these visualizations are solution components, they can be transported between organizations like any other customization. You can configure the attributes shown in the visualization by using the customization tools in the CRM Web application. There is no requirement to write code.

Visualization Example

external image IC766321.png


CRM SDK Support for Hierarchical Data


The OneToManyRelationshipMetadata class has a new IsHierarchical property that specifies whether the entity relationship should be considered hierarchical. There is also a new EntityMetadata.CanChangeHierarchicalRelationship managed property that you can use to control whether the hierarchical state of entity relationships included in your managed solutions can be changed. The following system entities have hierarchical relationships that can’t be changed: account, systemuser, product, and position. All of these settings can be configured using the customization tools in the web application without writing code, but developers can also define hierarchies programmatically using metadata APIs or query the metadata to understand which entity relationships are considered hierarchical.

Links

https://technet.microsoft.com/en-us/library/dn832068.aspx