One thing I’ve always wanted in Microsoft Dynamics CRM was the ability to create a one-to-one relationship between entities. According to the 8912 Customization in CRM 4.0 courseware, this is not supported. Keep in mind however, that many to many relationships were not supported in CRM 3.0, but we created them back then using a custom intersect entity and two or more 1 to M relationships.
I’ve given this a lot of thought, and it seems to me that you can create a one-to-one relationship using an interlocking pair of one to many relationships and two workflows to automate the link maintenance.
In this example, I wanted the ability to display outside contractors in the CRM service calendar while allowing CRM supported e-mail capabilities to communicate their task assignments. While CRM entities can support additional e-mail fields, I haven’t found an easy way to send e-mail to any e-mail attribute in CRM other than to Users, Leads, Contacts, and Accounts (or UCLA coined by Janice Hunt, one of the participants in the December CRM bootcamp in Cary, NC).
We start off by creating a one to many relationship with Contact as the primary entity and Facility / Equipment as the related entity. Note that we do not display the unused ‘many’ side of the relationship by selecting “Do not display” for the Navigation Pane Item for Primary Entity section of the General Tab on BOTH relationships. I did this to hide both ‘Many’ sides of the new relationships (the Associated Records list) from the user to avoid confusion.
Next,we create the reverse relationship with facility/equipment as the primary entity and contact as a related entity. Again, we do not display the unused ‘many’ side of the relationship by selecting “Do not display” for the Navigation Pane Item for Primary Entity section of the General Tab on BOTH relationships to hide the associated records list from confusing the user.
This creates the relationship structure, but we need to tie up some loose ends with two workflows. To make the example work, each entity must point to the other as the primary entity.
So we create a workflow associated with the equipment entity with automatic options: scope — business unit, start when record is created and when record attributes change.
We select contractor as the only attribute that the workflow will monitor for changes, then click OK.
the first line of code is a check condition to see if there is a Contractor link to be maintained,
then to verify if it needs to be updated.
If so, we need to update the contractor attribute of the contact entity to point back to this record, completing our one-to-one linkage.
When we publish this workflow, every time a new equipment record is created or the contractor attribute is changed, the resulting contact will also have its contractor attribute updated to point at the current equipment record.
To finish everything off and make the contractor relationship bi-directional, we need to create a second workflow associated with the Contact entity to maintain the contractor relationship whenever it’s changed. Unfortunately however, when I went to do that I found that the equipment entity does not appear in the list of related entities. I republish both entities, only to find that the problem persists. When I tested this with a custom test entity and the contact entity, I found that the updates were possible on both sides which confirms that this may be a CRM imposed limitation related to the Equipment entity.
In this particular case, this leaves us with a semi-functional one-to-one relationship that only works properly when you maintain the link from the equipment form. We will not expose the contractor relationship on the contact form, forcing all relationship changes to happen from the equipment record. Custom entities will not have this problem.
Now, workflow associated with either entity will support dynamic value access to to the opposing 1 to 1 entity attributes.
You also be able to access the opposing 1 to 1 entity attributes using advanced finds and system views.
The functional benefit of a one-to-one relationship is that you have more control which fields you can update and utilize from workflow processes, advanced find, and public views in Dynamics CRM 4.0.
Feel free to make any comments, suggestions or otherwise.
Merry Christmas, Happy New Year to all!!
Steve Noe, MCT