Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Show hide field based on checkbox help

Steve42
Tera Expert

I am frustrated with a script.  I want to show hide a field based on a checkbox.  I thought I had it working then it does not.(I'm new to some of this part of SNow)

What I have is a form with 3 checkboxes with fields under them that I need to do the same thing to. 
one example is
Field: Notification  type (checkbox)  
Field Notification_info   type(string)

I have tried a client script, a UI Policy and nothing seems to work. 

Logic i'm using:
when the form loads check
if the Notification Checkbox is checked, 
     then show  Notification Info field,
else 
     hide the notification field. 

The code I'm using:

function onCondition() {
var notifications = g_form.getValue('u_cr_notifications_t_f');
if(notifications == true){
	g_form.setDisplay('u_notification_info', true);
} else {
	g_form.setDisplay('u_notofication_info', false);
}
	
}

I believe the code is good, as it's just a simple If statement based on the value of notifications which if it's checked should be true and if unchecked should be false.

I don't know which is better a UI policy, a client script, a business rule (I doubt a business rule).

Could someone offer some sound advice as to what I can do to get this working. 

1 ACCEPTED SOLUTION

Onkar Pandav
Tera Guru

Hi Steve,

I think you should try it with UI PolicyNo need to write script.

 

First set "when to run" condition as: Notification --> is --> true

Then in "UI Policy Action" select the field to make it visible as: Field name=Notification info

and "

find_real_file.png

Please check it with UI Policy and let me know whether it is working or not.

--

Regards,

Onkar

View solution in original post

12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Use UI policy in such cases to avoid scripting; also ensure reverse if false is set to true on the UI policy

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Script is now working,   The When to apply is default (see second screen shot)
find_real_file.png

find_real_file.png

I I don't understand why this is not working

 

Hi,

If you only want to show/hide then don't use script; use UI policy actions instead which are available on the bottom section of the UI policy

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Mike Patel
Tera Sage

try client script

function onLoad() {