How to make the checkbox read - only using Client script

Pooja Khatri
Tera Contributor

I have four checkboxes in my Form , whenever the user selects one checkbox the other three should become read - only once the selection is done . It applies to all the four checkboxes , I tried implementing it using UI Policy but as the UI Policies are overridding I am not able to achieve it , how can I achieve it using client script ? Can any one help me with it .

Snippet of the checkboxes on the Form : 

 

find_real_file.png

6 REPLIES 6

quintenvandenb1
Giga Expert

Hello Pooja

The best and only way to get this working is by using 4 UI policies. Even if you would like to use a script, you still need 4 onChange client scripts for all the boxes.

About the overriding part, this should be your first priority to get these fixed.

A possible use case your are encountering right now:

UI policy A: if checkbox A checked)
-> checkbox A read only = false

-> checkbox B read only true

-> checkbox C read only true

The line I marked in red is might be your issue. Never inverse the logic manually. Let the system handle and leave all other details that you don't need on "Leave alone". This avoids conflicts.

Apart from AL of the above information:

I actually believe that what you got there is not a use case for checkboxes, but rather radio buttons like so:

find_real_file.png

 

This allows you to select just 1 option, always unchecking the other.

This variable is called Multiple Choice.

More information on that here: 

https://docs.servicenow.com/bundle/newyork-it-service-management/page/product/service-catalog-manage...

If any further questions, feel free to ask.

Please mark as helpful or correct if applicable.

 

Kind regards

 

Quinten

Hi @quintenvandenberghe  -- yes I am not using the below in my UI Policy 

 

UI policy A: if checkbox A checked)
-> checkbox A read only = false

the issue which I am facing is when I select 'One' from the checkbox the other three becomes read - only as expected , but when I select 'two' from the checkbox only ( 'three' and 'four') checkbox becomes read only and 'One' checkbox do not become read - only how can I fix this issue ?

 

The actualy scenario is whenever I select any one checkbox from the above the other three should become read only.

Prasad Dhumal
Mega Sage
Mega Sage

Hello Pooja,

to accomplish this, you can use UI Policies or Client Script

Way 1 : Apply 4 UI Policies according to the conditions.
Way 2 : Apply 4 On Change Client Scripts according to the conditions. 

Please mark as helpful or correct if applicable.

Kind regards

Prasad

Akhil42
Tera Contributor

Hi pooja,

Just refer the below screenshot,

And do the same catalog client scripts for the rest of variables(checkboxes) 

find_real_file.png

Kindly mark as Helpful ifcorrect,

Regards