I have a method that allows me to filter out certain options from an OptionSetValue field.
It works fine on a form field, but when that field is in the header, for a business process flow, it "works" as in, through debugging I see the options being cleared and re-added (only the ones that should be there), but once the form is rendered, all the options are visible...
Here's the method:
FilterOptionSetValues: function (fieldName, visibleOptions) {
var ctrl = Xrm.Page.getControl(fieldName);
var allOptions = ctrl.getOptions();
//clear current options
ctrl.clearOptions();
//loop through all options of optionset and if one is found in config element, add it.
for (var x = 0; x <= allOptions.length - 1; x++) {
if (visibleOptions.availableOptions.indexOf(parseInt(allOptions[x].value)) > -1) {
ctrl.addOption(allOptions[x]);
}
}
}
And here's how I call it:
FilterOptionSetValues('header_process_new_my_optionset_field', { stage: 1, availableOptions: [300000002, 300000003, 300000004] });
This code is called either in the form load event and the OnChange event of another fields (salesstage).
Is there something I'm missing? Seems like MS's own javascript is undoing my work here...
EDIT: When I put an OnChange
listener on header_process_new_my_optionset_field
, nothing happens when I change the value of that field in the header business process flow, but an onChange
listener on new_my_optionset_field
will be triggered by a change on that field either on the form or the header business process flow.
But running the logic above only on the field new_my_optionset_field
doesn't do the filtering for that same field up there in the business process flow.