Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

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

Yousaf
Giga Sage

Hi,

Can you try to put logs in if and else conditions.


***Mark Correct or Helpful if it helps.***

Rachel55
Mega Guru

In your pic, the variable name field has not been filled in.