One of the business requirements often heard from customers is “can we tag records in Dynamics CRM?”. Well, there is no out-of-the-box tagging feature available in Dynamics CRM. However, the product provides enough capability to create a record tagging framework without much effort!
I thought I would give a shot myself and came up with something like this.
Now from a high level it seems very simple: create a new Tag entity and link it to relevant entities (entity records to be tagged like Case, Account, Contact etc…) via a N:N relationship. Because a tag can be reused multiple times and a same Case or Contact record can be linked to multiple tags. This design would work only if the requirement around tagging is very basic. But if we want to bring out some kind of Business Intelligence out of this tagging like creating a nice dashboard with tag usage sliced and diced against Record Type, User, Time etc.. the N:N relationship would become a bottleneck. Because there would be more than one N:N relationship with Tag and at the Tag entity level there would be no mechanism to group them and display a consolidated metric.
To overcome this, we need to break this N:N relationship into two 1:N relationships by introducing a bridging entity. This entity would store the relationship details between a Tag and another entity record. We then can build nice consolidated metrics using this bridging entity because all entities would use the same bridging entity for maintaining their relationship with a Tag record. In this example, we would assume that we need to create tag Account, Case and Contact records.
So I decided to create the following two entities:
- Tag Literal, for storing the actual Tag
- Tag, the bridging entity (to store the link between a record and the Tag Data). I call it Tag as I intend to hide the fact from end user that they would be creating a link record.
Now let us jot down the steps of this customization:
- Create the Tag Literal entity with only one field : Tag, the Primary Field. Make sure this entity is hidden from all areas Sales, Service, Marketing, Settings.
- Create the Tag entity with the following fields. Make sure this entity is hidden from all areas Sales, Service, Marketing, Settings.
The lookup fields are actually N:1 relationships, create the relationships with entities to be tagged (e.g. Account, Contact or Case) in the following format:
- Then we would update the Tag entity Main form. Add only the Tag lookup field to the form. Hide the Primary Field called Tag from display. Do not add Account, Contact or Case lookup fields into the form. The form would look something like this:
- The next thing would be copying the Tag lookup field data to the Primary Field “Tag” of the Tag entity. We would use a Business Rule to first default the Primary Field to a static text “Tag” and after the form save the value would be changed to the Tag lookup field value by a Synchronous workflow.
- Now write Business Rule to populate data into Record Type field. This can also be done via a Synchronous Workflow. I just thought of keeping it simple with Business Rules. Below is an example with Case entity. We have repeat this rule for all the entities to be tagged.
- Once the framework is ready to store the data, now time to edit the ribbon to remove “Add Existing” button from Tag entity, so that the existing bridging relationship records are not displayed and user is always prompted to create a new relationship record with a Tag literal. Use Ribbon workbench to remove the button from the subgrid area.
- Create a Dashboard for displaying some metrics around the tags.
- Current Month Tags
- Current Month Tags Usage chart
- Current Month Tags Usage by Record Type chart
- Current Month Tags Usage by Day chart
- The last thing would be controlling access of who can create tag, who can tag a record and who can view tags etc.. Such stuff are very easy with the help of Dynamics CRM Security Roles. I am not delving much into it here.
Now publish all customization and the below is what a user can see.
Tags in a case form
Adding an Existing or a new Tag
Similarly the tags can be added to Accounts and Contacts records too. Once Tags are added, a nice Tagging Dashboard can look like this:
Hope this helps!