Javascript – Control OptionSet values
Views (1908)
Here is an example of a function to limit the values of an optionset, in this example I have a field called priority and want to be able to control when some options are selectable.
First off all, I define the options and text values that are possible in the optionset, theses are global variables.
var low = {value : 100000000, text : "Low"};
var medium = {value : 100000001, text : "Medium"};
var high = {value : 100000002, text : "High"};
var reallyHigh = {value : 100000003, text : "REALLY REALLY HIGH"};
Then this function, removes all of the current values and adds back just the ones I want to be selectable. This function is then calls from anywhere needed.
As either popOptSet(true); – to show all values.
Or popOptSet(false); – to show a restricted set.
function popOptSet(all) {
var pickList = Xrm.Page.getControl("new_priority");
var options = pickList.getOptions();
// *** Clear current items
for (var i = 0; i < options.length; i++) {
pickList.removeOption(options[i].value);
}
// *** Now add back just what is needed
if (all == true) {
pickList.addOption(reallyHigh);
}
pickList.addOption(low);
pickList.addOption(medium);
pickList.addOption(high);
}
Hopefully you can amend this concept for you own purposes.
Happy coding! J

Like
Report
*This post is locked for comments