
Hi All,
I'm trying to add PreSearch on lookup field incase of an option in optionset field and trying to remove it on another option. Add is working fine but removePreSearch isn't
onChangeProductType: function (executionContext) {
var formContext = executionContext.getFormContext();
if (formContext.getAttribute("ab_producttype").getValue() == 108730002) {
formContext.getControl("ab_product").addPreSearch(function () {
filterlookup(executionContext);
});
}
else {
formContext.getControl("ab_product").removePreSearch(function () {
filterlookup(executionContext);
});
}
},
filterlookup: function (executionContext) {
var formContext = executionContext.getFormContext();
var filter = "<filter type='and'><condition attribute = 'name' operator = 'like' value = '%Builders%' /><condition attribute='name' operator='like' value='%Single%' /><condition attribute='name' operator='like' value='%60%' /><condition attribute='name' operator='like' value='%Exterior%' /></filter>";
formContext.getControl("ab_product").addCustomFilter(filter);
},
*This post is locked for comments
I have the same question (0)Hi,
Please check if you have register the your method onChangeProductType on load as well as on change of product type. If still not working try below code (option 1), if this doesn't work then you can also achieve your requirement by option 2 code.
// Option 1
//==========================================================================
onChangeProductType: function (executionContext) {
var formContext = executionContext.getFormContext();
if (formContext.getAttribute("ab_producttype").getValue() == 108730002) {
formContext.getControl("ab_product").addPreSearch(filterlookup);
}
else {
formContext.getControl("ab_product").removePreSearch(filterlookup);
}
},
filterlookup: function () {
var filter = "<filter type='and'><condition attribute = 'name' operator = 'like' value = '%Builders%' /><condition attribute='name' operator='like' value='%Single%' /><condition attribute='name' operator='like' value='%60%' /><condition attribute='name' operator='like' value='%Exterior%' /></filter>";
formContext.getControl("ab_product").addCustomFilter(filter);
},
//==============================================================================
// Option 2
//==========================================================================
onChangeProductType: function (executionContext) {
var formContext = executionContext.getFormContext();
if (formContext.getAttribute("ab_producttype").getValue() == 108730002) {
formContext.getControl("ab_product").addPreSearch(function () {
filterlookup(executionContext);
});
}
else {
formContext.getControl("ab_product").removePreSearch(function () {
filterlookup(executionContext);
});
}
},
filterlookup: function (executionContext) {
var formContext = executionContext.getFormContext();
if (formContext.getAttribute("ab_producttype").getValue() == 108730002) {
var filter = "<filter type='and'><condition attribute = 'name' operator = 'like' value = '%Builders%' /><condition attribute='name' operator='like' value='%Single%' /><condition attribute='name' operator='like' value='%60%' /><condition attribute='name' operator='like' value='%Exterior%' /></filter>";
formContext.getControl("ab_product").addCustomFilter(filter);
}
else {
var filterAllProducts = "<filter type='and'><condition attribute = 'productid' operator='not-null'/></filter>";
formContext.getControl("ab_product").addCustomFilter(filterAllProducts);
}
},
//====================================
Hope this helps.