web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

JavaScript for Option set

(0) ShareShare
ReportReport
Posted on by 140

I have a Business requirement that, i have to filter off an option set values based up on another option set value

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

IT

Subtype Options :-

 

Equipment request, IT support, security , users

how could i implement this using JavaScript 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Kalana,

    Try to implement dependent optionset .

    docs.microsoft.com/.../gg594433(v=crm.8)

    balugajjala.wordpress.com/.../dependent-picklist-optionset-in-crm-2016

    You can also add remove dependent optionset options based one parent optionset field. Here is sample code -

    community.dynamics.com/.../289497

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    if you are not good in writing code. You can use below tool to generate it. Remember download the correct version according to your CRM version.

    crmoptionsets.azurewebsites.net

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    Try with this , I prepared code for you .

    You need to replace the options value and the field name , register the method in onchange of Type Field .

    function OptionSetAddRemove() {  
        var type = Xrm.Page.getAttribute("new_type").getValue();   // Replace Type field name   
        var optionSet = Xrm.Page.ui.controls.get("new_subtype");  // Replace Sub Type field name   
        var optionSetValues = optionSet.getAttribute().getOptions(); // retrieve All options of Option set field
        if(type = "1000000") // Replace the value of type = CRM
        {
            optionSet.clearOptions();
            optionSetValues.forEach(function (element) {
                if (element.value == "831260009" || element.value == "831260009" || element.value == "831260009" || element.value == "831260009" || element.value == "831260009")  // replace the value of options of Data Request, Development ,Physician services , Provider Measure, Technical Support
                    optionSet.addOption(element);
                if (element.value == "831260009" || element.value == "831260009" || element.value == "831260009" || element.value == "831260009" || element.value == "831260009")  // replace the value of options of Assembly, leader training, printing ,resource center, supply, support , Webinar
                    optionSet.removeOption(element);
    
            });
        }
        else if(type = "1000000") // Replace the value of type = Administrative
        {
            optionSet.clearOptions();
            optionSetValues.forEach(function (element) {
                if (element.value == "831260009" || element.value == "831260009" || element.value == "831260009" || element.value == "831260009" || element.value == "831260009")  // replace the value of options of Assembly, leader training, printing ,resource center, supply, support , Webinar
                    optionSet.addOption(element);
                if (element.value == "831260009" || element.value == "831260009" || element.value == "831260009" || element.value == "831260009" || element.value == "831260009")  // replace the value of options of  Data Request, Development ,Physician services , Provider Measure, Technical Support
                    optionSet.removeOption(element);
    
            });
    
        }
       
    }


  • Kalana1985 Profile Picture
    140 on at

    ohh Goutam, Thank you so much, ill test this and let you know how it goes, really appreciate your insight

  • Kalana1985 Profile Picture
    140 on at

    Hey Goutam, i add the attribute names and option-set values to the function and set to to trigger in type attribute onChange event, but it doesn't seems to be working, i was wondering maybe i should use Client API object module instead off Xrm.Objectmodule as you have use here ?

    and when using XRM. Object do i have to pass ExecutionContext as the perimeter? below is the refracted code that i use  

    function OptionSetAddRemove() {  

       var type = Xrm.Page.getAttribute("crmcust_type").getValue();   // Replace Type field name  

       var optionSet = Xrm.Page.ui.controls.get("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);

           });

       }

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    You should remove comma from all the  value .example -

    100,000,006   will be 100000006

  • Kalana1985 Profile Picture
    140 on at

    yes, after debugging for while I realize that, also its an int value not a string, thanks for your help

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans