Cascading Drop Downs

I am trying to implement code in an OnChange script that when one drop down is changed it changes the available values in another drop down. For instance one field is Finish Types: 2603, 2604 are options, when 2603 is select the Finish Options will have A, B, C, as selectable options, and 2604 would give you D, E, and F. Both fields are drop downs, but change the one changes the available values in the other. I couldn't find any example detailed enough for me to get started on this. Would appreciate any code examples that could be supplied. 

  • This has been a problem for as long as I've been dealing with Sage CRM (15 years). There is still no decent solution to this. Of all the potential solutions I've found, there is always a way to mess it up. You can get creative with using RemoveLookup but that only works when loading the screen and changing to edit mode. With the clientside scripting you might be able to do it more easily now. You will first need a custom content script on the page which contains a function to hold the states. The in the onchange you call that function based on the selected value. The function removes everything when the selected value is blank so you can't save anything in finish options without a value in finish type. When you choose a value in type, it reloads the correct values in options. You will need to make sure the correct values are set when doing this, so that when you save, the right form values are there in the dropdowns. It's a right pain to implement. It's a very commonly asked for feature. No decent solution exists on the forum that I've found. It's a common thing in many other CRM systems.

  • Thank you for the response Vega, don't suppose you could through together a brief example of this function, you are referencing towards.

  • My solution requires the values of the selection lists to be in a specific format.
    If the parent selection lists has the options
    1
    2
    3

    The "Child" selection list's options must start with the relevant parent option plus a hyphen e.g.

    1-A
    1-B
    2-A
    2-C
    3-D

    Selecting "1" in the parent dropdown will filter the child dropdown so only options starting with "1-" are available.

    Put the following in your custom/js folder: https://gist.github.com/JohnKingsbury/6e103d3e9f2b865c431ccfbb4fcb8842

    And in the customcontent of a screen, it can be used like

    crm.ready(function(){
      filterSelect("comp_c_myparent", "comp_c_mychild");
    })

  • Here is the one I use, this goes into the Custom Content of the page 

    And works on the Code in the first field being something like A, B, C and the second field A1, A2, B1, C1. The coding matches the letters 

    <script language="javascript">
    crm.ready(function(){
    FilterSelection("#case_field1","#case_field2");
    FilterSelection("#case_field2","#case_field3");
    FilterSelection("#case_field3","#case_field4");
    //add as many as you want here

    });

    function FilterSelection(main, linked)
    {
    var list = $(linked).html();
    $(main).change(function(e) {
    var selected = $(main).val();
    $(linked).html(list);
    if (selected == "--None--") return;
    $(linked).children("option:not([value^='"+selected+"'])").remove();
    $(linked).append("<option value='' selected=true>--None--</option>");

    });
    }

    </script>

  • Sweet thank you Matthew, this has got me going in the right directions. However there is a small issue. When first coming to this page this doesn't automatically set those values as it only runs when I change the original field. What is the method for setting the available values when first coming to this page and clicking the Change button