Remove option of OptionSet based on form selection.

Suppose we have one OptionSet field with below values:

{1 – First }

{2 – Second }

{3 – Third }

We want to hide “Third” option from the OptionSet on form selection then the below code works fine for us :

function removeOptionSetOption() {
var formName = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();
if (formName == ‘Information’) {//Suppose we have form called “Information”
//Check options.
var pickList = Xrm.Page.getControl(“OptionSetName”);
var options = pickList.getOptions();

for (var i = 0; i < options.length; i++)
if (options[i].value == 3) // Third
{
pickList.removeOption(options[i].value);
return;
}
}
}

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s