CRM 2011 Dialog: how to filter a lookup field

From what I’ve discovered while playing with dialogs, when using a lookup field, the filter criteria that you put on the field are simply ignored by the dialog. By default, the dialog will set the lookup default view to the concerned entity’s lookup view. That can be a problem sometimes. To solve this, here is another highly unsupported customization that I’ve come up with today.


1. Find the guid of your dialog (just open it and look for the id parameter in the url)
2. Create the view you want to use to filter the lookup, and get its guid (same method)
3. Open this file: “C:Program FilesMicrosoft Dynamics CRMCRMWebCSdialogrundialog.aspx”
4. Open the dialog, and using Chrome for example, find the lookup img’s id. It will look like this: “InteractionStep7”
5. At the end of the script tag, add the following function:

function setId(dialogGuid, viewGuid) {
if (window.location.href.indexOf(dialogGuid) > -1) {
var lookupImg = document.getElementById(‘InteractionStep7’);
if(!lookupImg) {
setTimeout(setId, 100);
} else {
lookupImg.setAttribute(‘defaultviewid’, viewGuid);
6. Then in the ┬ásame file, make the body tag like this, with the appropriate guids of course: <body onload=”setId(‘123124435’, ‘123124345’)”>
Finding the guids are obivous.
Then editing the rundialog file, please note that this is highly unsupported of course.
Looking at the dialog page’s dom elements, you will see that the lookup image has an id. But that id is not set when onload is called. Probably some javascript executed there to get the dialog’s data.
This is why I use a timeout, that just waits for that id to be set. When the element is found, then I update the default view id, ie the view that will be use in the lookup window url.
And that’s it!

Leave a Reply

Your email address will not be published. Required fields are marked *