Hello,
We basically took the DependentOptionSet.js file from the Microsoft SDK and modified it to work on fields in the business process flow and not just on fields on a form. However, we are upgrading to D365 and this code dosent work on the field in the business process flow anymore. Has anybody else ran into this?
Below is the code snippit:
function subTypeInit(executionContext) { var formContext = executionContext.getFormContext(); // get formContext var stageName = formContext.data.process.getActiveStage().getName(); if (stageName == "somestage") { var parentField = "new_someparentfield"; var childField = "new_somechildfield"; formContext.getControl("header_process_new_someparentfield").getAttribute().addOnChange(setDepenetOptionSet(executionContext, parentField, childField)); } else { return; } } function setDepenetOptionSet(executionContext, parentField, childField) { var formContext = executionContext.getFormContext(); // get formContext for (var depOptionSet in SDK.DependentOptionSet.config) { var DependentOptionSet = SDK.DependentOptionSet.config[depOptionSet]; /* Match the parameters to the correct dependent optionset mapping*/ if ((DependentOptionSet.parent == parentField) && (DependentOptionSet.dependent == childField)) { /* Get references to the related fields*/ var ParentField = formContext.getControl("header_process_" + parentField).getAttribute(); var ChildField = formContext.getControl("header_process_" + childField).getAttribute(); /* Capture the current value of the child field*/ var CurrentChildFieldValue = ChildField.getValue(); /* If the parent field is null the Child field can be set to null */ if (ParentField.getValue() == null) { ChildField.setValue(null); ChildField.setSubmitMode("always"); ChildField.fireOnChange(); // Any attribute may have any number of controls // So disable each instance var controls = ChildField.controls.get() for (var ctrl in controls) { controls[ctrl].setDisabled(true); } return; } for (var os in DependentOptionSet.options) { var Options = DependentOptionSet.options[os]; var optionsToShow = Options.showOptions; /* Find the Options that corresponds to the value of the parent field. */ if (ParentField.getValue() == Options.value) { var controls = ChildField.controls.get(); /*Enable the field and set the options*/ var runOnce = true; for (var ctrl in controls) { if (!runOnce) break; runOnce = false; controls[ctrl].setDisabled(false); //This is a workaround to get the child controls to refresh //controls[ctrl].clearOptions(); var sub_category = formContext.ui.controls.get("header_process_" + childField); sub_category.clearOptions(); for (var option in optionsToShow) { controls[ctrl].addOption(optionsToShow[option]); } } /*Check whether the current value is valid*/ var bCurrentValueIsValid = false; var ChildFieldOptions = optionsToShow; for (var validOptionIndex in ChildFieldOptions) { var OptionDataValue = ChildFieldOptions[validOptionIndex].value; if (CurrentChildFieldValue == OptionDataValue) { bCurrentValueIsValid = true; break; } } /* If the value is valid, set it. If not, set the child field to null */ if (bCurrentValueIsValid) { ChildField.setValue(CurrentChildFieldValue); } else { ChildField.setValue(null); } ChildField.setSubmitMode("always"); ChildField.fireOnChange(); break; } } } } }
Behavior in D365
Behavior in Dynamics 2015