Clear Select Box values on checkbox check

nicolemccray
Tera Expert

When a particular checkbox is checked, and the 'req_level_safe' value does not equal 'none', the user will receive a pop up message (working currently), and the values of 2 select box variables should be cleared.  My script will not clear the values:

 

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

//Type appropriate comment here, and begin script below
var accOnly = g_form.getValue('access_only_checkbox');
var reqSafe = g_form.getValue('req_level_safe');
var reqFac = g_form.getValue ('req_facility_clearance');
var message = 'If subcontractor will have or require access only at Government or contractor facility, then Safeguarding may only be NONE.';

if(accOnly == 'true' && reqSafe != 'none'){
g_form.setValue(reqFac, '');
g_form.setValue(reqSafe,'');
alert(message);


}
}

1 ACCEPTED SOLUTION

DScroggins
Kilo Sage
Use the name of the actual variables to clear the values like so: g_form.clearValue('req_level_safe'); g_form.clearValue ('req_facility_clearance');

View solution in original post

5 REPLIES 5

Andrew Barnes -
ServiceNow Employee
ServiceNow Employee

vinothkumar
Tera Guru

If it is a check box and you want to uncheck then, you have to set the value as false rather than "'

 

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

//Type appropriate comment here, and begin script below
var accOnly = g_form.getValue('access_only_checkbox');
var reqSafe = g_form.getValue('req_level_safe');
var reqFac = g_form.getValue ('req_facility_clearance');
var message = 'If subcontractor will have or require access only at Government or contractor facility, then Safeguarding may only be NONE.';

if(accOnly == 'true' && reqSafe != 'none'){
g_form.setValue(reqFac, false); //If it is checkbox, set value as false
g_form.setValue(reqSafe,false); //If it is checkbox, set value as false
alert(message);


}
}

 

They are not check boxes, they are select boxes.

DScroggins
Kilo Sage
Use the name of the actual variables to clear the values like so: g_form.clearValue('req_level_safe'); g_form.clearValue ('req_facility_clearance');