Friday, March 4, 2011

Simple Filtered Lookup based on Picklist Values


I had a parent entity containing records classified into 2 different disease categories ('Diabetes' and 'Cholestrol').
In my related entity, there was a picklist which had the above 2 disease categories. The criteria was that when the user selected a particular disease cateogry in the picklist, the parent entity lookup should show as a pop-up showing only the corresponding disease category records.
Ex: If the user selects ‘Diabetes’ in the picklist, then the lookup should pop-up showing only records of type ‘Diabetes’. After some searching, I found this blog:http://advantageworks.blogspot.com/2008/02/pseudo-filtered-lookup-dialog-in.html, which was describing a similar scenario. Here is how I implemented this:
1. I went into customizations and opened my parent entity.
2. Then I clicked on “Forms and views” and opened the lookup view.
3. Then I clicked on “Add Find Columns” and selected “Disease Category” column.
4. Saved and Published the entity
5. Next, I opened my related entity’s form.
6. In the onchange event of my picklist, I wrote the following code:

if(crmForm.all.new_Picklist.SelectedText=="Diabetes")
{
var criteria= 'Diabetes';
crmForm.all.new_parentLookupId.additionalparams =  'search=' + criteria;
crmForm.all.new_parentLookupId.click(); // Launch the parent lookup as a popup.
} 
7. Save and publish the related entity. So, basically this is the same as opening the lookup and typing ‘Diabetes’ in the search box of the lookup. It’s not filtered in a strict sense.
–Srihari.

No comments:

Post a Comment