How to detect toggle is enabled in UI builder page?

ajayraina14
Tera Contributor

I have created a settings page using UI builder. In that page I have a toggle and if the toggle is enabled then I want to trigger a scheduled job.

How we can check whether the toggle is enabled/disabled?

 

Thanks

Ajay

1 ACCEPTED SOLUTION

Kevin83
ServiceNow Employee
ServiceNow Employee

One way to do this is to:
1. set up a boolean state variable such as toggleState

Screenshot 2024-10-10 at 10.40.13 AM.png

2. Bind the checked property to your state variable

Screenshot 2024-10-10 at 10.40.23 AM.png

3. Update the state variable when the toggle changes

Screenshot 2024-10-10 at 10.40.54 AM.png

4. you can then access the state variable later such as in this script I wrote when a button is clicked

Screenshot 2024-10-10 at 10.46.24 AM.png

View solution in original post

5 REPLIES 5

Kevin83
ServiceNow Employee
ServiceNow Employee

One way to do this is to:
1. set up a boolean state variable such as toggleState

Screenshot 2024-10-10 at 10.40.13 AM.png

2. Bind the checked property to your state variable

Screenshot 2024-10-10 at 10.40.23 AM.png

3. Update the state variable when the toggle changes

Screenshot 2024-10-10 at 10.40.54 AM.png

4. you can then access the state variable later such as in this script I wrote when a button is clicked

Screenshot 2024-10-10 at 10.46.24 AM.png

ajayraina14
Tera Contributor

@Kevin83  Thanks for the reply

I followed the steps but in the log it is always showing as false.

Can you please confirm if its giving correct value at your end.

 

Thanks,
Ajay

Kevin83
ServiceNow Employee
ServiceNow Employee

Yes I checked it on my end and it is logging the value correctly

Screenshot 2024-10-11 at 10.01.01 AM.png

ajayraina14
Tera Contributor

@Kevin83  Below is the configuration which I have done, The only difference is that I want to trigger the toggle not with the button, the toggle on/off should be triggered by the toggle itself. Below are the screenshots:

The value is not changing when toggle is changed to on/off.