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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Getting values of a dropdown based on response from another field

(0) ShareShare
ReportReport
Posted on by 62

I have a option set column called "Business Unit" and the options are 

"Edge"

"Core"

"Cloud"

Then I have another option set column called "Business category" and the options are

"Hardware"

"Software"

"Services"

If I select any option on "Business Unit" then the dropdown from "Business Category" should pop up based on the option, I selected in "Business Unit"

For eg:-

1. If I select "Edge", then only "Hardware" should pop up 

2. If I select "Core" then "Hardware" and "Software" should pop up

3. f I select "Cloud" then "Hardware" and "Software" and "Services" should pop up

We are trying with JScript in CRM, but it is showing some error. Can anyone help me out how to write a script to achieve this process. I have to do this on priority.

  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    You can use DOSM (Dependent Option Set Manager)

    https://github.com/GuidoPreite/DOSM

    Install the managed solution and launch the app

  • Suggested answer
    Tamilarasu Arunachalam Profile Picture
    593 on at

    Hi Rajath,

            As of now Business rules does not support setting values to the Multi select option set field. So, you can do it with JavaScript. The below code JavaScript might help you

    function optionSetPopup(executionContext){
        var formContext=executionContext.getFormContext();
        var businessUnitValue=formContext.getAttribute("comp_bunit").getValue();
        var businessCategoryValue=formContext.getAttribute("comp_bcat");
        switch(businessUnitValue){
            case 528830000:
                businessCategoryValue.setValue([528830000]);
                break;
            case 528830001:
                businessCategoryValue.setValue([528830000,528830001]);
                break;
            case 528830002:
                businessCategoryValue.setValue([528830000,528830001,528830002]);
                break;
        }
    }

    pastedimage1670670289185v2.pngpastedimage1670670317448v3.pngpastedimage1670670340493v4.png

    If this helps you, please verify my answer

  • Rajath Krishna S Profile Picture
    62 on at

    Hi Tamilarasu,

    Thank you for your help, I got my script and it's working now. Can you pls suggest me how to write the same script using array concept? as it will enhance the script.

    I am pasting my script here, pls tell me how to achieve using array

    var B_line = window.B_line || {};

    (function() {

       this.formOnLoad = function (executionContext){

       var formContext = executionContext.getFormContext();

       var businessarea = formContext.getAttribute("new_buniessarea21").getValue();

    var businessline = formContext.getAttribute("new_buniessline21")

       if (businessarea == "Edge")

    {

           businessline.clearOptions();

    businessline.addOption({value: 100000000, text: 'Hardware'});

       businessline.addOption({value: 100000001, text: 'Software'});

       businessline.addOption({value: 100000002, text: 'Services'});

       }

    if (businessarea == "Core")

    {

           businessline.clearOptions();

    businessline.addOption({value: 100000000, text: 'Hardware'});

       businessline.addOption({value: 100000001, text: 'Software'});

       businessline.addOption({value: 100000002, text: 'Services'});

    businessline.addOption({value: 100000003, text: 'Software Subscription'});

       }

    if (businessarea == "Cloud")

    {

           businessline.clearOptions();

       businessline.addOption({value: 100000001, text: 'Software'});

       businessline.addOption({value: 100000002, text: 'Services'});

       }

    }

    }).call(B_line)

  • Suggested answer
    Tamilarasu Arunachalam Profile Picture
    593 on at

    Rajath,

    I think you don't need to use addOption() because it adds new option to optionset, you have to use setValue() as i did in my code

    Please verify my answer, if you found it useful

  • Rajath Krishna S Profile Picture
    62 on at

    Sure I will use that SeValue() option , but can you help me to achieve the same using array as it will enhance the code and number of lines will be reduced.

  • Suggested answer
    Tamilarasu Arunachalam Profile Picture
    593 on at

    As per my understanding to your question. By default the values from Multi-select optionset is in the form of array. you can set your value to this array as i did.

  • Rajath Krishna S Profile Picture
    62 on at

    Hi Tamilarasu,

    I am trying an alternative way mentioned in internet using array, can you help me out where I'm wrong as I'm getting an error.

    var B_line_arr = window.B_line_arr || {};

    (function() {

       this.formOnLoad = function (executionContext){

       var formContext = executionContext.getFormContext();

    var businessarea = formContext.getAttribute("new_buniessarea21").getText();

    var businessline = formContext.getAttribute("new_buniessline21")

    if(businessarea=="Edge")

    {

      var arr = [{value: 100000000, text: 'Hardware'},

      {value: 100000001, text: 'Software'},

      {value: 100000002, text: 'Services'}];

          for(var i=0;i<=arr.length;i++)

      {

      businessline.clearOptions();

      businessline.addOption({value: arr[0].value, text: arr[0].text});

      }

    }

    }  

    }).call(B_line_arr)

    Error info

    pastedimage1670913593356v1.png

  • Suggested answer
    Tamilarasu Arunachalam Profile Picture
    593 on at

    Rajath,

    As i already told selecting an option and adding an option are different.

    Do you want to select an option or add an option to the option set?

    If you found this useful, like or verify my answer. That keeps me motivated

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Syed Aqib Raza Profile Picture

Syed Aqib Raza 103

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 83 Most Valuable Professional

#3
11manish Profile Picture

11manish 54 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans