Dropdown options in the SP form display

aagnihotri
Tera Contributor

Hi all , 

I  want to show a dropdown in the region such that  when Type of VDI is Network then only United State should occur in the dropdown . And when i Select Type of VDI as end user then it should show  " United States , ABC  and  XYZ " options . And when i select it as DEV it should show "US, UK, CA,MA" . 

aagnihotri_0-1741215544970.png

 

I  did run a piece of code and its not working  and i am confused if it is because of the single line text that client catalog script is not able to understand when its fetching the values because the type of vdi is read only  . My client script is on change because the option in the dropdown gets selected when single line text - type of vdi gets changed . 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    var regionMapping = {
        "Network": ["United States"],
        "Dev": ["United States", "ABC", "XYZ"],
        "End User": ["US, UK, CA,MA"]
    };

    var regionField = 'region';

    // Clear the existing options
    g_form.clearOptions(regionField);

    // Check if the selected VDI type exists in the mapping
    if (regionMapping.hasOwnProperty(newValue)) {
        var regions = regionMapping[newValue];

        // Add a placeholder first option
        g_form.addOption(regionField, '', '--Select a Region--');

        // Populate the dropdown with the relevant regions
        for (var i = 0; i < regions.length; i++) {
            g_form.addOption(regionField, regions[i], regions[i]);
        }
    }
}

 

Any suggestion over the code can be helpful . 

1 REPLY 1

J Siva
Tera Sage

Hi @aagnihotri 

First thing if you are aware of all possible values of "Type of VDI" question, then better make it as a select box (drop down). So that it'll reduce the human error.

Next, in the second question, while creating choices like US, UK, keep the name as US and it's value as Network, End user.

 

For eg. For the VDI type question, the choices are 

Name.                Value

1. DEV.                 1

2. Network          2

3.End user.          3

 

For the Region Question, the choices would be like,

Name.            Value

US.                  1,2 ( As US belongs to both Network and Dev, I'm using their backend values from the previous question)

UK.                   3 (As it belongs only to End user)

 

Once you done with this, then change the type of the second question as reference and refer that to choice table where you can see all the drop down values which you created previously.

 

Now in the second question update the ref qualifier as

javascript&colon;"question=<sys_id of the second question>^valueLIKE"+current.variables.vdi_type;

 

That's, now your second question will show the drop down choices based on the first question's answer.

Let me know if you need any help to implement this.