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.

Client Script Help

Walter Toney
Tera Expert

I'm looking for a sample client script to do the following 

 

I have a Select box Variable on a SC named "Group Role"

based on the selection

FT

FTA

FATA-5

 

I want the following Variables to become Visible/Mandatory/hidden

 

org name

org access

org rights

Justification

Dual Role

 

if 

FT                                                               FTA                                          FATA-5

Mandatory -org name                              Mandatory -org name            Hide - org name

Mandatory - org access                           Visible - org access                 Hide - org access

Mandatory - org rights                            Mandatory - org rights            Hide - org rights

Visible - Justification                               Visible - Justification               Manadatory - Justificaiton

Hide -Dual Role                                       Hide -Dual Role                       Manadatory - Dual Role

 

any suggestions

 

1 ACCEPTED SOLUTION

SAI VENKATESH
Kilo Patron
Kilo Patron

Hi @Walter Toney 

 

Here is the client Script ( but my suggestion you can go for UI Policies)

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }
    var orgName = g_form.getValue('org_name');
    var orgAccess = g_form.getValue('org_access');
    var orgRights = g_form.getValue('org_rights');
    var justification = g_form.getValue('justification');
    var dualRole = g_form.getValue('dual_role');

    if (newValue === 'FT') {
        g_form.setMandatory('org_name', true);
        g_form.setMandatory('org_access', true);
        g_form.setMandatory('org_rights', true);
        g_form.setVisible('justification', true);
        g_form.setVisible('dual_role', false);
    } else if (newValue === 'FTA') {
        g_form.setMandatory('org_name', true);
        g_form.setVisible('org_access', true);
        g_form.setMandatory('org_rights', true);
        g_form.setVisible('justification', true);
        g_form.setVisible('dual_role', false);
    } else if (newValue === 'FATA-5') {
        g_form.setVisible('org_name', false);
        g_form.setVisible('org_access', false);
        g_form.setVisible('org_rights', false);
        g_form.setMandatory('justification', true);
        g_form.setMandatory('dual_role', true);
    }
}

 

Thanks and Regards

Sai Venkatesh

View solution in original post

1 REPLY 1

SAI VENKATESH
Kilo Patron
Kilo Patron

Hi @Walter Toney 

 

Here is the client Script ( but my suggestion you can go for UI Policies)

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }
    var orgName = g_form.getValue('org_name');
    var orgAccess = g_form.getValue('org_access');
    var orgRights = g_form.getValue('org_rights');
    var justification = g_form.getValue('justification');
    var dualRole = g_form.getValue('dual_role');

    if (newValue === 'FT') {
        g_form.setMandatory('org_name', true);
        g_form.setMandatory('org_access', true);
        g_form.setMandatory('org_rights', true);
        g_form.setVisible('justification', true);
        g_form.setVisible('dual_role', false);
    } else if (newValue === 'FTA') {
        g_form.setMandatory('org_name', true);
        g_form.setVisible('org_access', true);
        g_form.setMandatory('org_rights', true);
        g_form.setVisible('justification', true);
        g_form.setVisible('dual_role', false);
    } else if (newValue === 'FATA-5') {
        g_form.setVisible('org_name', false);
        g_form.setVisible('org_access', false);
        g_form.setVisible('org_rights', false);
        g_form.setMandatory('justification', true);
        g_form.setMandatory('dual_role', true);
    }
}

 

Thanks and Regards

Sai Venkatesh