To display option in the choice of select box in catalog item

Shalika
Tera Expert

I have a variable - request_type of type select box which has 3 options --> create, modify and decommission. I have another variable ci_type of type select box which has 5 options --> infrastructure, server, computer, hardware and cloud services. 

The requirment is that when modify option is selected in request_type then cloud services option should be visible in the ci_type select box. If create or decomission option is selected in request_type only 4 options under ci_type option should be visible that are infrastructure, server, computer, hardware.

How to achieve this?

1 ACCEPTED SOLUTION

Kalyani Jangam1
Mega Sage
Mega Sage

Hi Shalika,

Used Onchange client script of req_type variable in below code

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        g_form.clearOptions('ci_type', '');
        return;
    }
    if (newValue == 'modify') {
        g_form.removeOption('ci_type', 'infrastructure');
        g_form.removeOption('ci_type', 'server');
        g_form.removeOption('ci_type', 'computer');
        g_form.removeOption('ci_type', 'hardware');
        g_form.addOption('ci_type', 'cloud services', 'Cloud Services');
    } else if (newValue == 'create' || newValue == 'decommission') {
        g_form.removeOption('ci_type', 'Cloud Services');
        g_form.addOption('ci_type', 'infrastructure', 'Infrastructure');
        g_form.addOption('ci_type', 'server','Server');
        g_form.addOption('ci_type', 'computer', 'Computer');
        g_form.addOption('ci_type', 'hardware', 'Hardware');
    }

    //Type appropriate comment here, and begin script below

}

Mark Answer Helpful and Correct, if it will work

View solution in original post

3 REPLIES 3

JP - Kyndryl
Kilo Sage

Hi Shalika,

In the Choice List where your values are defined,  use the "Dependent Value" field to relate ci_type values with the request_type ones.

As examples,  look how the incident.category and incident.subcategory are related using that Dependent Value field.

Regards.

JP

Regards,
JP

JP - Kyndryl
Kilo Sage

Hi Shalika,

https://community.servicenow.com/community?id=community_question&sys_id=59ce5250db0b9054190b1ea668961962

Regards.

JP

 

Regards,
JP

Kalyani Jangam1
Mega Sage
Mega Sage

Hi Shalika,

Used Onchange client script of req_type variable in below code

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        g_form.clearOptions('ci_type', '');
        return;
    }
    if (newValue == 'modify') {
        g_form.removeOption('ci_type', 'infrastructure');
        g_form.removeOption('ci_type', 'server');
        g_form.removeOption('ci_type', 'computer');
        g_form.removeOption('ci_type', 'hardware');
        g_form.addOption('ci_type', 'cloud services', 'Cloud Services');
    } else if (newValue == 'create' || newValue == 'decommission') {
        g_form.removeOption('ci_type', 'Cloud Services');
        g_form.addOption('ci_type', 'infrastructure', 'Infrastructure');
        g_form.addOption('ci_type', 'server','Server');
        g_form.addOption('ci_type', 'computer', 'Computer');
        g_form.addOption('ci_type', 'hardware', 'Hardware');
    }

    //Type appropriate comment here, and begin script below

}

Mark Answer Helpful and Correct, if it will work