Published: January 1, 2008
Data requires context to be meaningful. For example, details related to the activities of a sales call are more valuable when viewed in the context of information about the potential customer. Microsoft Dynamics CRM provides the most common entity relationships to provide this context. However, your organization's needs may be unique and in certain cases you may want to add a field on a form so that users can reference a record in another record type (entity). This type of field is called a lookup.
For example, each Microsoft Dynamics CRMOpportunity record has an Owner field that represents the Microsoft Dynamics CRMuser who is assigned to close the opportunity. If you want to assign another Microsoft Dynamics CRMuser to be a secondary owner for the opportunity, you can add a lookup field so that user can also be linked to the opportunity.
To add a lookup field, you need the System Administrator or System Customizersecurity role, or equivalent privileges.
|
|
Understand entity relationships |
|
|
Create your new lookup attribute |
|
|
Add your new lookup attribute to a form |
|
|
Test your new lookup field |
|
|
Publish and confirm your customization |
Every field in a Microsoft Dynamics CRM form has a corresponding entity attribute. In most cases, if you want to create a new field you would start by creating a new entity attribute. Lookup fields are different. While most types of new entity attributes are created in the Attributes area of an entity, lookup attributes are created automatically when you create an entity relationship.
There are two types of entity relationships you can create:
Hierarchical Relationships represent an entity relationship where one record stores a unique reference to another record. The lookup field you are adding will let a user set this reference to another record. The record that has the lookup field is often called the child record. The record that is referenced in the lookup field is called the parent record.
For example, a sales opportunity may include a number of quotes provided to a customer. There is a hierarchical relationship between the Opportunity entity and the Quote entity that provides a lookup field in the Quote form to associate a quote record with a specific opportunity record. A quote record is a child to the opportunity record. Each opportunity may have more than one quote associated with it.
You choose the type of record that will be available in the lookup field when you define an entity relationship. The parent record type is called the primary entity. The child record type is called the related entity.
You must start from one of these entities so there are two options to choose from when creating a hierarchical relationship.
1:N (1-to-Many) Relationships represent hierarchical relationships created or viewed from the primary entity. Any one record from the primary entity can be referenced by many records from the related entity.
N:1 (Many-to-1) Relationships represent hierarchical relationships created or viewed from the related entity. Many records from the related entity can reference any one record from the primary entity.
Note
Despite the fact that there are two separate hierarchical relationship options it is important to remember that either option can be used to achieve the same result. You do not have to go to both entities to create a relationship between them.
N:N (Many-to-Many) Relationships are not hierarchical because the records do not store a unique reference to another record. There is no lookup field on the form in an N:N Relationship. Both records are considered peers. They both look like parent records because they display a list of all the other records they are related to in an associated view.
For example, in a sales opportunity there may be several competitors involved. Any number of competitors may be involved in any number of sales opportunities. Therefore, a N:N Relationship exists that allows competitors to be added to a list of competitors in an opportunity record. From each competitor record you can see a list of all the opportunities that competitor is involved with.
Because a single user can act as a secondary owner for many opportunities, you'll create a hierarchical relationship between the Opportunity entity and the User entity. Because you want the lookup field to be on the Opportunity form, the User entity must be the primary entity in the entity relationship.
In the Navigation Pane, click Settings, click Customization, and then click Customize Entities.
Double-click the Opportunity entity.
Under Details, click N:1 Relationships.
On the Actions toolbar, click New Many-to-1 Relationship.
In the Relationship: New form, in the Primary Entity field, select User.
In the Display Name field, type Secondary Owner.
If you want to make this a required field for every Opportunity, select Business Required in the Requirement Level field.
Select Use Custom Label in the Display Option field.
Note
By default, creating this entity relationship will add a new associated view to the User entity form that will show all the Opportunities where a user is a secondary owner. The default label for this associated view would be the plural name for the related entity. In this case it would be Opportunities This might be misunderstood to mean that this user is the owner of the opportunities. The name of the link should not be ambiguous.
Type Secondary owner for: in the Custom Label field.
In the Relationship Behavior section, in the Type of Behavior field, you must keep the default setting of Referential.
Note
Each entity can only have one relationship with a Type of Behavior that is Parental or Configurable Cascading. Because there is a preexisting relationship between Opportunity and User that uses the Parental Type of Behavior the only options available to you are Referential or Referential, Restrict Delete.
Selecting Referential, Restrict Delete would prevent the user record from being deleted if that user were Secondary Owner for any Opportunities.
Click Save and Close. This leaves the Entity: Opportunity form open. Keep this form open, because you will use it in the next procedure.
You can position the new lookup attribute on the Opportunity form wherever it makes most sense for your users.
On the Entity: Opportunity form, under Details, click Forms and Views, and then in the list, double-click Form.
Select the section where you want to add the Secondary Owner lookup field. To select a section, click the section header, and a green line is displayed surrounding the section.
Click Add Fields. Your new lookup attribute appears on the list.
Select Secondary Owner, and then click OK.
Click Save, which will leave the Form: Opportunity form open. Keep this form open, because you will use it in the next procedure.
Before you publish a customization to a form, preview it so that you can verify that it works as you expect.
On the Form: Opportunity form, on the Preview menu, click Create Form.
Note
The Create Form represents the form used when a new record is created. Unless you are testing client-side scripts, test with this form should be sufficient.
Click the
Lookup
button next to the Secondary Owner field.
A list of
Microsoft Dynamics CRM
users appears. Click OK or
Cancel
to close the
Look Up Records
dialog box, and then, on the
File
button, click
Close
to close the preview window.
Click Save and Close.
On the Entity: Opportunity form, click Save and Close.
For your users to see the changes you've made, you must publish the customization.
On the Customize Entities page, on the More Actions menu, click Publish All Customizations.
Confirm that the new Secondary Owner lookup field appears in an Opportunity record and set the value to a Microsoft Dynamics CRMuser.
Save the Opportunity record and click the Secondary Owner field to open to the User record.
Confirm that the Secondary Owner List displays in the correct area of the User form.
Note
You can now create new Opportunities or link this user as the Secondary Owner to existing Opportunities from the User form.