Created
September 3, 2018 19:21
-
-
Save anilsomasundaran/0a3724c877ec4ae09219a792cc271a29 to your computer and use it in GitHub Desktop.
How to populate the dependent optionset based on a range (child optionset value should maintain a range based on the parent option-set values) in ms crm dynamics 365
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function filterOptionSet(parentOptionSet, childOptionSet, maxOptionRange) { | |
//Gets the parent option set control from the CRM page context | |
var primaryOptionSet = Xrm.Page.getAttribute(parentOptionSet); | |
//Reads the currently selected option in the parent option set | |
var selectedOption = primaryOptionSet.getSelectedOption(); | |
//In other way, reads the control of the child option set | |
//where the dependent values to be populated | |
var dependentOptionSet = Xrm.Page.ui.controls.get(childOptionSet); | |
//calls the interal function for filter the child optionset values. | |
filterDependentOptionSet(selectedOption, dependentOptionSet, maxOptionRange); | |
} | |
function filterDependentOptionSet(selectedOption, dependentOptionSet, maxOptionRange) { | |
var optionValues = dependentOptionSet.getAttribute().getOptions(); | |
dependentOptionSet.clearOptions(); | |
if (selectedOption) { | |
var min = selectedOption.value; | |
var max = (min + maxOptionRange) - 1; | |
for (var index = 0; index < optionValues.length; index++) { | |
var optionValue = optionValues[index]; | |
var value = optionValue.value; | |
if (value >= min && optionValue.value <= max) { | |
dependentOptionSet.addOption(optionValue); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment