Skip to main content

Notifications

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
    RE: Getting values of a dropdown based on response from another field

    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

  • Rajath Krishna S Profile Picture
    Rajath Krishna S 62 on at
    RE: Getting values of a dropdown based on response from another field

    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
    RE: Getting values of a dropdown based on response from another field

    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
    Rajath Krishna S 62 on at
    RE: Getting values of a dropdown based on response from another field

    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
    RE: Getting values of a dropdown based on response from another field

    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
    Rajath Krishna S 62 on at
    RE: Getting values of a dropdown based on response from another field

    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
    RE: Getting values of a dropdown based on response from another field

    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

  • Suggested answer
    Guido Preite Profile Picture
    Guido Preite 54,087 Super User 2024 Season 1 on at
    RE: Getting values of a dropdown based on response from another field

    You can use DOSM (Dependent Option Set Manager)

    https://github.com/GuidoPreite/DOSM

    Install the managed solution and launch the app

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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans