Skip to main content

Notifications

Customer Service forum

OptionSet values

Posted on by 140

I'm trying to set a Option set value based up on another option set value, my requirements as below,

based on Case Type option set the subtype option set should filter off

 

If

 

Type =CRM

 

Subtype Options :-

 

Data Request, Development ,Physician services , Provider Measure, Technical Support

 

If

Type = Administrative

 

Subtype Options :-

 

Assembly, Leader training, Printing ,Resource center, Supply, Support , Webinar

 

If

Type =IT

Subtype Options :-

 

Equipment request, IT support, Security , Users

here is the JavaScript im using ATM

function OptionSetAddRemove(executionContext) {
var formContext = executionContext.getFormContext();
var type = formContext.getAttribute("crmcust_type").getValue(); // Replace Type field name
var optionSet = formContext.getControl("new_subtype"); // Replace Sub Type field name
var optionSetValues = optionSet.getAttribute().getOptions(); // retrieve All options of Option set field

if (type == "155,330,001") // the value of type = CRM
{
optionSet.clearOptions();
optionSetValues.forEach(function (element) {
if (element.value == "100,000,000" || element.value == "100,000,001" || element.value == "100,000,002" || element.value == "100,000,003" || element.value == "100,000,004") // replace the value of options of Data Request, Development ,Physician services , Provider Measure, Technical Support
optionSet.addOption(element);
if (element.value == "100,000,005" || element.value == "100,000,006" || element.value == "100,000,007" || element.value == "100,000,008" || element.value == "100,000,009" || element.value == "100,000,010" || element.value == "100,000,011" || element.value == "100,000,012" || element.value == "100,000,013" || element.value == "100,000,014" || element.value == "100,000,015") // replace the value of options of Assembly, leader training, printing ,resource center, supply, support , Webinar
optionSet.removeOption(element);

});
}

}

i have set above code to Type Attribute onChange event , the code is not doing anything at the moment, there is no error, but code is not working, any help would greatly appreciate 

Categories:
  • Kalana1985 Profile Picture
    Kalana1985 140 on at
    RE: OptionSet values

    Yes Ajith, Apparently that value is a Int , i did remove the string value as well as the , separating the numbers, that did the trick, code is working now, thanks!

  • Verified answer
    AjitPatra Profile Picture
    AjitPatra 469 on at
    RE: OptionSet values

    Hi Kalana,

    Can you please remove "," from the values in your conditions and see if it works e.g. change your first if condition to : if (type == "155330001")

    Thanks,

    Ajit

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,818 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,147 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans