Kids, don't try this at home!

Tips & Tricks for C#, ASP.NET and CRM

Pre-filter the Dynamics CRM Form Assistant

Time for another trick...

While trying to reduce as many clicks as possible one customer insisted that they want the form assistant pre-filtered, most of you are aware that this is not supported. Google Bing said it's unsupported and I couldn't see any useful info so opened up the IE Dev Toolbar and found that there are 2 elements; a textbox for searching via form assistant and the search icon (findValue and btnGo), now all that's needed is to put our pre-filtering text into it and force click that button!

On the form onLoad event

function autoFilter() {
    try {
        // check to see if we need to pre-filter
        if (crmForm.all.somefield.DataValue != null) {
            var search = document.getElementById("findValue");
            // inject our pre-filter value into the form assistant
            search.value = crmForm.all.somefield.DataValue;
            // force it to do the search
            document.getElementById("btnGo").click();
            // clear the value since we're on a timeout if the user switches rapidly it will give invalid results
            search.value = "";
        }
    } catch (e) { } // ignore errors
}

// lookup you want to filter, note the _d
var lookup = document.getElementById("lookup_d");
// timeout is needed because crm generates the form assistant dynamically
// need a better solution than timeout...any suggestions?
lookup.attachEvent('onclick', function(event) { setTimeout(autoFilter, 1500) });

Here's an example of a parent/child lookup being pre-filtered via the form assistant

Enjoy!

Posted: May 27 2010, 09:35 PM by gperera | with 2 comment(s)
Filed under:

Comments

Pre-filter the Dynamics CRM Form Assistant | Roman's Blog said:

Pingback from  Pre-filter the Dynamics CRM Form Assistant | Roman's Blog

# October 19, 2010 8:18 AM

Technical problem troubleshooting: Filter form assistant based on another field said:

Pingback from  Technical problem troubleshooting: Filter form assistant based on another field

# February 9, 2011 12:23 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)