Javascript – Control OptionSet values

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 = Xrm.Page.getAttribute("new_priority").getOptions();

  // *** Clear current items
  for (var i = 0; i < options.length; i++) {

  // *** Now add back just what is needed
  if (all == true) {


Hopefully you can amend this concept for you own purposes.

Happy coding! J

2 thoughts on “Javascript – Control OptionSet values

  1. Hi,
    it seems that your code contains a bug.

    Please pay attention to the difference between Xrm.Page.getControl(“new_priority”) and Xrm.Page.getAttribute(“new_priority”)

    “getControl” doesn’t implement getOptions method.

    Your code should be something like this:
    for (var i = 0; i < Xrm.Page.getAttribute("new_priority").getOptions().length; i++)

    Giorgio –


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s