Quantcast
Viewing latest article 2
Browse Latest Browse All 10

Grab those lookup values

CRM uses the Primary-Attribute (not to be confused with primary key) for many UI features and functions such as the Associated Views and the Lookup View and the default field for Primary-Attribute is Name.  Unfortunately you can’t have a lookup field or picklist for your Primary Attribute so in the example below even though we select a Trip from the Trips lookup the Name (primary attribute) would need to be filled in manually. 

 In this example imagine you have an Entity called Trips and an entity called Trip Packages.  A Trip Package is related to a Trip and it is a required value.  When you select a Trip from the Trip lookup you want to set the value of the Primary-Attribute/Name so that when Trip packages are searched for they will always contain the name of the base Trip.

 The solution is simple but I’ve seen some wild examples that are much more complex.

Here’s the one line of code to be added to the lookup field controls OnChange Event.

crmForm.all.new_name.DataValue = crmForm.all.new_authorid.DataValue[0].name;

 You could easily concatenate other fields to the Name/ Primary-Attribute as well.  I might add trip date and sponsor name for example.  I would use the same code with the appropriate control names to grab those lookup values:

crmForm.all.new_name.DataValue = crmForm.all.new_sponsorid.DataValue[0].name + crmForm.all.new_authorid.DataValue[0].name + crmForm.all.new_tripdate.DataValue;

 I know we can make this example more elegant with the use of variables and string functions but let’s leave it simple for easy digestion.

 Happy coding!


Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing latest article 2
Browse Latest Browse All 10

Trending Articles