How to add lookup filter on custom javascripts

This function bind to form onload “OnLoad”, after calling the “preFilterLookup” function. This method access to form control and add to “addPreSearch” events. In events calling the custom fetchxml functions.

 


function OnLoad() {
preFilterLookup();
}

function preFilterLookup() {
Xrm.Page.getControl("formcontrolelementid").addPreSearch(function () {
addLookupFilter();
});
}

function addLookupFilter() {
fetchXml = "<filter type='and'>"
fetchXml += "<condition attribute='logicalname' operator='eq' value='value' ></condition>";
fetchXml += "</filter>";
Xrm.Page.getControl("formcontrolelementid").addCustomFilter(fetchXml);
}

#custom-js, #lookup, #lookup-filter, #web-resource

Advertisements