Share

Using a Lookup Entity in CRM 2011 to handle default values and field lengths on a form

Business Problem:

A recent client of ours had extremely complex rules regarding creating new records. When the lookup was used the form needed to auto fill and limit the number of characters that can be entered. We could have accomplished this via JavaScript, but it soon became apparent that it would become unmanageable quickly. It would also be a management nightmare if the business rules changed tomorrow.

Solution:

Customer Effective, Inc. created a lookup entity that stored the lookup value, default values and length restrictions for fields. User selects a lookup value, the on-change event calls JavaScript which loops thru the lookup entity and set default values and control field lengths on the form.

Here are the pieces you need to build in order to replicate this functionality.

1.) Create a new lookup entity. We called it “Processors”. There are two main sections in this lookup entity. The first part we called “Field Lengths.” The following section called “Default Values” (See screenshots below) shows samples of the default values that to be set on the form.

This section allows an administrator to limit the length of fields on a form. When creating the length fields in the lookup entity make the attribute names the same as the attribute on the other entity. This makes writing the JavaScript to loop thru the form and setting the attribute length easier.

[responsive]clip_image002[/responsive]

(Field Lengths)

Sample default values are listed below. Each processor lookup option could have had different default values. When creating these attributes we also made the attribute name the same but added “_def” to the attribute.

[responsive]clip_image003[/responsive]

(Default Values)

2.) Create an entity that will use the new lookup to store the actual selected values based on the lookup value selected. This example entity called “Host Parameters.” A user selects a processor and the form status are “create” state we loop up thru the lookup entity to set field lengths and set the default values using JavaScript.

Click on Create Host Parameter

[responsive]clip_image005[/responsive]

Select a Processor and see default fields get populated automatically based on the lookup entity.

[responsive]image[/responsive]

Field lengths are now restricted based on the lookup entity.

[responsive]clip_image010[/responsive]

3.) Create a new JavaScript web resource that calls the lookup entity. The JavaScript needs to retrieve the field lengths and default values from selected lookup value. Use JavaScript to set the field lengths and default values on the form.

If this is something your organization could leverage, feel free to reach out to Customer Effective at info@customereffective.com