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

You're welcome.

HI Onkar,

 

where can I find the example ? Could you please help me with that ? 

Hi,

You can search on YouTube for that. Below is the one link that can be helpful.

https://www.youtube.com/watch?v=0VQV9KCQxpQ

--

Regards,

Onkar.