The CreatorCon Call for Content is officially open! Get started here.

Setting field to null based on true/false field

carlocsa
Kilo Expert

Hi ServiceNow Gurus,

In have 2 fields:

u_field_a is a text field, u_field_b is a true/false field

by default, u_field_a contains a value (ex. "string") and u_field_b is true

what i want to achieve is to clear u_field_a when u_field_b is set to false.

please help.

thank you very much.

Carlo

 

1 ACCEPTED SOLUTION

Ujjawal Vishnoi
Mega Sage

Hi Carlo,

You can also use onChange client script for field u_field_b if you want to clear the field a as soon as we change the field b to true.Please refer screenshot below.

find_real_file.png

script-----

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(newValue=='false')
g_form.setValue('u_field_a','');

}

 

Hope this helps.

Regards

Ujjawal

View solution in original post

6 REPLIES 6

Jon Barnes
Kilo Sage

You can create a new Business rule for this. You can do it without scripting.

Set the Filter Condition in your BR to u_field_b Changes to false

In the Actions tab, use set Field Values to set u_field_a to blank.

Tick the insert and update boxes and save your BR. this should give you what you want.

Ujjawal Vishnoi
Mega Sage

Hi Carlo,

You can also use onChange client script for field u_field_b if you want to clear the field a as soon as we change the field b to true.Please refer screenshot below.

find_real_file.png

script-----

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(newValue=='false')
g_form.setValue('u_field_a','');

}

 

Hope this helps.

Regards

Ujjawal

thanks! this is exactly my code except my "false" was not inside ''.

Doing an onchange client script is fine, but I would also recommend creating the business rule as well. The reason is because sometimes people will update that field outside a form, and in those cases, your client script won’t fire. So my best practice is to put logic like this in a BR, and then ā€œback it upā€ with a client script if you want immediate feedback