How to check two check boxes when other two check boxes are checked

Satyapriya
Mega Sage
 Open the form of Existing Catalog Item: Standard Laptop
Use Case 1:
1. Configure two new check boxes below existing "Adobe Photoshop" checkbox
Check Box 1: Laptop
Check Box 2: Desktop
2. When you check "Adobe Acrobat" then "Laptop" should be automatically selected or checked and "Desktop" checkbox should be hidden
3. When you uncheck "Adobe Acrobat" then "Laptop" should be automatically unchecked and "Desktop" checkbox should be visible
4. When you check "Adobe Photoshop" then "Desktop" should be automatically selected and "Laptop" checkbox should be hidden
5. When you uncheck "Adobe Photoshop" then "Desktop" should be automatically unchecked and "Laptop" checkbox should be visible
6. When both "Adobe Acrobat" and "Adobe Photoshop" are selected then both "Laptop" and "Desktop" should be visible and auto-checked (or auto selected)
 
I have written two client scripts:
The first one is 
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var abode = g_form.getValue('acrobat');
var photo = g_form.getValue('photoshop');
if (abode == 'true') {
g_form.setValue('laptop', 'true');
g_form.setVisible('desktop', 'false');
} else if (abode == 'true' && photo == 'true') {
g_form.setVisible('desktop', 'true');
g_form.setVisible('laptop', 'true');
g_form.setValue('laptop', 'true');
g_form.setValue('desktop', 'true');
} else {
g_form.setValue('laptop', 'false');
g_form.setVisible('desktop', 'true');
}
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
The second one is :
    var photo = g_form.getValue('photoshop');
    var abode = g_form.getValue('acrobat');
    if (photo == 'true') {
        g_form.setVisible('laptop', 'false');
        g_form.setValue('desktop', 'true');
    } else if (photo == 'true' && abode == 'true') {
        g_form.setVisible('laptop', 'true');
        g_form.setVisible('desktop', 'true');
        g_form.setValue('desktop', 'true');
        g_form.setValue('laptop', 'true');
    }else{
g_form.setVisible('laptop', 'true');
        g_form.setValue('desktop', 'false');
}
}
The usecases 1,2,3,4,5 works but the last one didn't work.
Please anyone tell me How can I achieve this scenario.
2 ACCEPTED SOLUTIONS

Vishal Birajdar
Giga Sage

Hi @Satyapriya 

 

You should write most generic case in separate if-else loop like below.

 

if (abode == 'true') {
g_form.setValue('laptop', 'true');
g_form.setVisible('desktop', 'false');
} else {
g_form.setValue('laptop', 'false');
g_form.setVisible('desktop', 'true');
}

 

if (abode == 'true' && photo == 'true') {
g_form.setVisible('desktop', 'true');
g_form.setVisible('laptop', 'true');
g_form.setValue('laptop', 'true');
g_form.setValue('desktop', 'true');
}

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

We have to write two onchange client script 

One is for change of abode and other one is for change of photoshop 

View solution in original post

4 REPLIES 4

Vishal Birajdar
Giga Sage

Hi @Satyapriya 

 

You should write most generic case in separate if-else loop like below.

 

if (abode == 'true') {
g_form.setValue('laptop', 'true');
g_form.setVisible('desktop', 'false');
} else {
g_form.setValue('laptop', 'false');
g_form.setVisible('desktop', 'true');
}

 

if (abode == 'true' && photo == 'true') {
g_form.setVisible('desktop', 'true');
g_form.setVisible('laptop', 'true');
g_form.setValue('laptop', 'true');
g_form.setValue('desktop', 'true');
}

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Thanks Vishal ,

             This is working properly.

Lakshmi Prasan4
Tera Contributor

Hi,

 

On which variable we have to write the on change client script. Is it adobe?

We have to write two onchange client script 

One is for change of abode and other one is for change of photoshop