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) });
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!