Advertisement
Guest User

Untitled

a guest
Oct 17th, 2013
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SDK.DependentOptionSet.filterDependentField = function(parentField, childField) {
  2.     for ( var depOptionSet in SDK.DependentOptionSet.config) {
  3.     var DependentOptionSet = SDK.DependentOptionSet.config[depOptionSet];
  4.     /* Match the parameters to the correct dependent optionset mapping */
  5.     if ((DependentOptionSet.parent == parentField) && (DependentOptionSet.dependent == childField)) {
  6.         /* Get references to the related fields */
  7.         var ParentField = Xrm.Page.data.entity.attributes.get(parentField);
  8.         var ChildField = Xrm.Page.data.entity.attributes.get(childField);
  9.         /* Capture the current value of the child field */
  10.         var CurrentChildFieldValue = ChildField.getValue();
  11.  
  12.         /* If the parent field is null the Child field can be set to null */
  13.         if (ParentField.getValue() == null) {
  14.         ChildField.setValue(null);
  15.         ChildField.setSubmitMode("always");
  16.         ChildField.fireOnChange();
  17.  
  18.         // Any attribute may have any number of controls
  19.         // So disable each instance
  20.         var controls = ChildField.controls.get()
  21.  
  22.         for ( var ctrl in controls) {
  23.             controls[ctrl].setDisabled(true);
  24.         }
  25.         return;
  26.         }
  27.  
  28.         for ( var os in DependentOptionSet.options) {
  29.         var Options = DependentOptionSet.options[os];
  30.         var optionsToShow = Options.showOptions;
  31.         /*
  32.          * Find the Options that corresponds to the value of the parent
  33.          * field.
  34.          */
  35.         if (ParentField.getValue() == Options.value) {
  36.             var controls = ChildField.controls.get();
  37.             /* Enable the field and set the options */
  38.             for ( var ctrl in controls) {
  39.             controls[ctrl].setDisabled(false);
  40.             controls[ctrl].clearOptions();
  41.  
  42.             for ( var option in optionsToShow) {
  43.                 controls[ctrl].addOption(optionsToShow[option]);
  44.             }
  45.  
  46.             }
  47.             /* Check whether the current value is valid */
  48.             var bCurrentValueIsValid = false;
  49.             var ChildFieldOptions = optionsToShow;
  50.  
  51.             for ( var validOptionIndex in ChildFieldOptions) {
  52.             var OptionDataValue = ChildFieldOptions[validOptionIndex].value;
  53.  
  54.             if (CurrentChildFieldValue == OptionDataValue) {
  55.                 bCurrentValueIsValid = true;
  56.                 break;
  57.             }
  58.             }
  59.             /*
  60.              * If the value is valid, set it. If not, set the child
  61.              * field to null
  62.              */
  63.             if (bCurrentValueIsValid) {
  64.             ChildField.setValue(CurrentChildFieldValue);
  65.             } else {
  66.             ChildField.setValue(null);
  67.             }
  68.             ChildField.setSubmitMode("always");
  69.             ChildField.fireOnChange();
  70.             break;
  71.         }
  72.         }
  73.  
  74.     }
  75.     }
  76. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement