Clear Y/N Variable With Client Script

Wasdom_Kung
Tera Guru

Hello,

I am trying to find a way to clear the values or set them back to 'None' for some Y/N variables if one of two previous variables change. This is to prevent any UI issues as this item has a few options that may show variables that shouldn't due to later values still being present.

 

I've tried a few different attempts but can't see to get it working, here's my latest:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
	
	var loginChoice = g_form.getValue('u_can_this_user_currently_login_to_service_now');
	var licenseChoice = g_form.getValue('u_does_this_user_require_a_fulfiller_license');

    if (loginChoice.changes || licenseChoice.changes){
		
        g_form.clearValue('u_do_you_require_this_users_license_to_be_transferred_to_someone_else');
        g_form.clearalue('u_do_you_require_groups_to_be_added_or_removed');
    }
}


Any assistance would be great, thanks!

1 ACCEPTED SOLUTION

I attempted this method but it wouldn't work either.

I also tried splitting it into two different client scripts, on change for each of the two fields login and licence, but it doesn't set the values of the latter Y/N variables to None either:

 

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

    if (oldValue != newValue) {
        g_form.setValue('u_do_you_require_this_users_license_to_be_transferred_to_someone_else', '');
        g_form.setValue('u_do_you_require_groups_to_be_added_or_removed', '');
    }
}

 

 

Edit: The above does work, I just forgot to change the variable that the onChange script watches.

View solution in original post

2 REPLIES 2

Teja11
Giga Guru

Hi @Wasdom_Kung ,

 

try the below code

 

var yesNoVar = g_form.getReference('variable_name');
yesNoVar.value = '';
yesNoVar.checked = false;

 

Regards,

Teja

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

I attempted this method but it wouldn't work either.

I also tried splitting it into two different client scripts, on change for each of the two fields login and licence, but it doesn't set the values of the latter Y/N variables to None either:

 

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

    if (oldValue != newValue) {
        g_form.setValue('u_do_you_require_this_users_license_to_be_transferred_to_someone_else', '');
        g_form.setValue('u_do_you_require_groups_to_be_added_or_removed', '');
    }
}

 

 

Edit: The above does work, I just forgot to change the variable that the onChange script watches.