Wednesday, 26 February 2014

Filter lookups based on fetch XML CRM 2011/CRM2013

BElow is an example of how to filter a lookup on a form by Fetch XML. This can be usefull when you need to filter by more than one condition or a very custom  conditions

function preFilterLookup() {    Xrm.Page.getControl("parentaccountid").addPreSearch(function () {
     addLookupFilter();
     addLookupFilter();   });}function addLookupFilter() {
    
    var email = Xrm.Page.getAttribute("emailaddress1").getValue();    if (email != null) {
        fetchXml = 
        fetchXml = "<filter type='and'><condition attribute='emailaddress1' operator='eq' value='" + email + "' /></filter>";            Xrm.Page.getControl("parentaccountid").addCustomFilter(fetchXml);
    }
}
    }}

THe preFilterLookup() function needs to be called from the onload

No comments:

Post a Comment