Defaulting the search criteria of a lookup

Option 1 – Hard coding the search criteria with a text value
 

crmForm.all.INSERTLOOKUPFIELD.additionalparams = "search=INSERTTEXTSEARCHCRITERIA";

Option 2 – Filtering the lookup search with a value from another lookup

For example when you want to filter the primary contacts lookup on an Account with only the contacts associated to that account by default. The code is split into a function and then  the code to call the function.

Function

document.FilteredLookup = function(criteria, lookup)
    {
    if(criteria == null || lookup == null)
        {
        return;
        }
     var filterCriteria = IsNull(criteria.DataValue) ? "" : criteria.DataValue[0].name;
     lookup.additionalparams = "search=" + filterCriteria;
    }

Code to call the function 

document.FilteredLookup(crmForm.all.INSERTFIELD, crmForm.all.INSERTFIELD);

 
 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s