Hi All, i’m trying to filter lookup based on a option set, however i found a couple of JS codes in the net and neither one of them seems to be working, so i’m guessing i’m not doing something correct in the code:
Here is the structure:
Entity: Replacement (voss_replacement)
Fields: Component Type (voss_device_component_type) – global option set (Component Type – voss_component_type)
Entity: External repair (voss_externalrepair)
Fields: Replacement (voss_replacement_part) – Lookup, Component type (voss_repair_component_type) – global option set (Component Type – voss_component_type),
Here is the code:
function filter_Lookup_Fields()
{
if (Xrm.Page.getControl(‘voss_device_component_type’) != null)
{
Xrm.Page.getControl(‘voss_replacement_part’).addPreSearch(addFilter);
}
}
function addFilter() {
var problemcategoryoptionset ;
var fetchQuery;
try {
problemcategoryoptionset = Xrm.Page.getControl(‘voss_device_component_type’).getAttribute().getValue();
if (Xrm.Page.getControl(‘voss_device_component_type’) != null && Xrm.Page.getControl(‘voss_device_component_type’).getAttribute().getValue() != null) {
fetchQuery = “<filter type=’and’>” +
“<condition attribute=’statecode’ operator=’eq’ value=’0′ />” +
“<condition attribute=’voss_device_component_type’ operator=’eq’ value='” + problemcategoryoptionset + “‘ />” +
“</filter>”;
//add custom filter
Xrm.Page.getControl(‘voss_replacement_part’).addCustomFilter(fetchQuery);
}
}
catch (e) {
Xrm.Utility.alertDialog(‘addFilter Error: ‘ + (e.description || e.message));
}
}
Any help is appreciated.
Thank you in advance!