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. 

  • 0

    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.

  • 0 in reply to Vega

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

  • 0

    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");
    })

  • 0 in reply to John Kingsbury

    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>

  • 0 in reply to Matthew Shaw

    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

  • 0 in reply to DKarkanica

    I think (as my dev gave me the script) you just need to call it, so provide it a name (so change function() to be function(NewName)) and then you can call on this from the CreateScript of the main fields 

  • 0 in reply to John Kingsbury
    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

    Can You make a GIF or a video for this part?


    Noah Greatson
    https://www.worktime.com/ Project

  • 0 in reply to Matthew Shaw

    How do you deal with situations where I have a dropdown list where some of the options appear for more than one option in the parent list? For example:

    Parent list:
    A
    B
    C
    D

    If I choose A, I need options 1, 2, and 3 shown in the child list. If I choose B, I need options 2, 3, and 4 to appear. In this example choosing either A or B, both will have the common elements 2 and 3 shown in the child plus their additional unique ones.

  • 0 in reply to Vega

    My original script would require you to make multiple sub-values 

    Another way to do this is to approach this differently. Ignoring my script you could do it this way. Lets say we have two Selection fields 

    Selection-A (e.g. A,B,C,D)

    Selection-B (e.g. 1,2,3,4,5,6,7,8,8,9,10)

    And we want A to control B. But you want values in B to be available to multiple values. in A. 

    Create a 'Master' B list in the normal fashion 

    Then within Translations you manually create an entire new list of items (e,g, capt_family='Selection-B1') which only has (1,2,3,4) and then do it again for capt_family='Selection-B2. Which has (1,3,5,7) 

    Then on your screen within CRM you could put an OnChange script in on the Selection-A field that If Selection-A = A then change the capt_family of Selection-B to be Selection-B1 but if you change it to B then change it to Selection-B2

    So long when you build the values you use the same codes in B1 and B2 just choosing to not include them all. 

  • 0 in reply to Matthew Shaw

    Now that is thinking out side the box Mr. Shaw, I utilized something similar to what you said however I just hard coded each value in my code. Thanks again in time switching to your recommendation pertaining to Capt_family may very well happen.

  • 0 in reply to DKarkanica

    I've implemented it once at a customer site with just two selection fields, but built 4 custom capt_familys for the sub level, but works a treat. It is a headache for maintenance but so long you're not needing to add values all the time it should be OK. 

  • 0

    There is (was) a script on Greytrix website which I commented on a few years ago here:

    www.sagecity.com/.../370907