Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SDK.DependentOptionSet.filterDependentField = function(parentField, childField) {
- 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 = Xrm.Page.data.entity.attributes.get(parentField);
- var ChildField = Xrm.Page.data.entity.attributes.get(childField);
- /* 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 */
- for ( var ctrl in controls) {
- controls[ctrl].setDisabled(false);
- controls[ctrl].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;
- }
- }
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement