Hello,
I have 2 lookups. On the first one is a javascript which sets a presearchfilter for the second one. When Value "Printpodukte" or in english printproducts is picked the presearchfilter gets set.
however when go back to the first lookup and pick anything else, the filter wont get removed. Below is the code. I already searched in the forums and tried the advices but nothing worked.
I hope anyone finds my failure
function filterLookup() {
try {
if (Xrm.Page.getControl("xxx_productfamily") != null && Xrm.Page.getControl("xxx_productfamily") != undefined) {
if (Xrm.Page.getAttribute('xxx_productfamily').getValue()!=null) {
var product = Xrm.Page.getAttribute('xxx_productfamily').getValue()[0].name;
if (product == "Printprodukte")
{
Xrm.Page.getControl("productid").addPreSearch(preSearchHandler);
}
else
{
alert('remove');
Xrm.Page.getControl("productid").removePreSearch(preSearchHandler);
}
}
}
} catch (e) {
throw new Error(e.Message);
}
}
function preSearchHandler() {
addCustomeLookupFilter();
}
function addCustomeLookupFilter() {
try {
fetchxml = "<filter type='and'><condition attribute = 'productstructure' operator = 'eq' value = '3' /></filter >";
Xrm.Page.getControl("productid").addCustomFilter(fetchxml);
}
catch (e) {
throw new Error(e.Message);
}
}