Hide/Show choice list in client Script

Fabrizio Joaqui
Mega Guru

Hi, i want to show/hide choice list based on the value the user selects, i tried to do it with the below script but its not working, can anyone help me? Thanks in advance.

 

the script remove but not show when the user selects other values:

 

 

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

    //Type appropriate comment here, and begin script below
    if (newValue == '1' || newValue == '2') {
        g_form.removeOption('u_esito', 'istr');
    }else{
		alert('hi!');
		g_form.addOption('u_esito', 'istr','Istruzione');
	}
	
}

 

1 ACCEPTED SOLUTION

AnubhavRitolia
Mega Sage
Mega Sage

Hi @Fabrizio Joaqui 

 

Please try below code:

 

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

    //Type appropriate comment here, and begin script below
    if (newValue != '1' && newValue != '2') {
      g_form.addOption('u_esito', 'istr','Istruzione');
    } else {
	g_form.removeOption('u_esito', 'istr');
	}
	
}

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

View solution in original post

1 REPLY 1

AnubhavRitolia
Mega Sage
Mega Sage

Hi @Fabrizio Joaqui 

 

Please try below code:

 

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

    //Type appropriate comment here, and begin script below
    if (newValue != '1' && newValue != '2') {
      g_form.addOption('u_esito', 'istr','Istruzione');
    } else {
	g_form.removeOption('u_esito', 'istr');
	}
	
}

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023