How to remove/add options based on another field in Service Portal.

Spike236
Tera Contributor

Hello all,

 

I'm trying to get this one working but without any luck. I want to change the choice options in the Subtype field based on what the requestor will choose in the Type field.  I have created a  catalog client script for this.

It should be as follow: Indoor - Climbing stair,Pushup

Outdoor - Cycling,Running

 

Thank you for any help!

find_real_file.png

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var typeChoice = g_form.getValue('type');
    if (typeChoice == 'indoor') {
        g_form.removeOption('subtype', 'running');
        g_form.removeOption('subtype', 'cycling');
		g_form.addOption('subtype', 'pushup');
		g_form.addOption('subtype', 'climbing_stairs');
    } else if (typeChoice == 'outdoor') {
        g_form.removeOption('subtype', 'pushup');
        g_form.removeOption('subtype', 'climbing_stairs');
		g_form.addOption('subtype', 'running');
		g_form.addOption('subtype', 'cycling');
    }
}

 

find_real_file.png

1 ACCEPTED SOLUTION

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var typeChoice = g_form.getValue('type');
    if (typeChoice == 'indoor') {
            g_form.removeOption('subtype', 'running');
        g_form.removeOption('subtype', 'cycling');

		g_form.addOption('subtype', 'pushup');
g_form.addOption('subtype', 'CHOICE_VALUE', 'CHOICE
_LABEL', );
		g_form.addOption('subtype', 'CHOICE_VALUE', 'CHOICE
_LABEL', );
    } else if (typeChoice == 'outdoor') {
 g_form.removeOption('subtype', 'pushup');
        g_form.removeOption('subtype', 'climbing_stairs');
		g_form.addOption('subtype', 'CHOICE_VALUE', 'CHOICE
_LABEL', );
		g_form.addOption('subtype', 'CHOICE_VALUE', 'CHOICE
_LABEL', );
    }
}

@Pavel Hruby DID YOU GIVE THE VARIABLE NAME AS TYPE IN ON CHANGE CLIENT SCRIPT ?

AFTER CHECKING IT TYR THIS SCRIPT i gave above

Hope this helps 

 

View solution in original post

6 REPLIES 6

Mohith Devatte
Tera Sage
Tera Sage

Hello @Pavel Hruby 

try this 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var typeChoice = g_form.getValue('type');
    if (typeChoice == 'indoor') {
     g_form.clearOptions('subtype');
		g_form.addOption('subtype', 'pushup');
		g_form.addOption('subtype', 'climbing_stairs');
    } else if (typeChoice == 'outdoor') {
  g_form.clearOptions('subtype');
		g_form.addOption('subtype', 'running');
		g_form.addOption('subtype', 'cycling');
    }
}

 

Hope this helps 

please mark my answer correct if this helps you

Hello Mohith,

thank you for the answer. However, this will remove the options from the Subtype field altogether. I tried to change the variable name in the catalog client script but it did not work.

 

find_real_file.png

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var typeChoice = g_form.getValue('type');
    if (typeChoice == 'indoor') {
            g_form.removeOption('subtype', 'running');
        g_form.removeOption('subtype', 'cycling');

		g_form.addOption('subtype', 'pushup');
g_form.addOption('subtype', 'CHOICE_VALUE', 'CHOICE
_LABEL', );
		g_form.addOption('subtype', 'CHOICE_VALUE', 'CHOICE
_LABEL', );
    } else if (typeChoice == 'outdoor') {
 g_form.removeOption('subtype', 'pushup');
        g_form.removeOption('subtype', 'climbing_stairs');
		g_form.addOption('subtype', 'CHOICE_VALUE', 'CHOICE
_LABEL', );
		g_form.addOption('subtype', 'CHOICE_VALUE', 'CHOICE
_LABEL', );
    }
}

@Pavel Hruby DID YOU GIVE THE VARIABLE NAME AS TYPE IN ON CHANGE CLIENT SCRIPT ?

AFTER CHECKING IT TYR THIS SCRIPT i gave above

Hope this helps 

 

Hello Mohith,

your solution with choice value and choice label works. Thank you very much:)