Make choice variable Visible &Mandatory based on app value and other choices value

Manohararuna
Tera Contributor

Hello Everyone,

 

      I have one requirement,

      The catalog item having the App value -reference type(reference table gm-app table)

     Choice1 Variable -reference type(reference table -gm_add_il_table)

 Choice2 Variable -reference type(reference table -gm_add_il_table)

Choice3 Variable -reference type(reference table -gm_add_il_table)

gm_app table and gm_add_il table are interlinked with name field 

suppose if select app value then script check app value having the choice1 value ,if Yes then make it Mandatory

based on chice1 value it check the choice2 having value ,if yes make it visible and mandatory

based on chice2 value it check the choice23having value ,if yes make it visible and mandatory

 

if the choice are not having the values then make all hide like below

Manohararuna_0-1757409200897.png

Manohararuna_2-1757410808620.png

if select app value , if it's having only choice1 then it's visible and it's mandatory also

Manohararuna_1-1757410783496.png

but some applications are not unique like below 

Manohararuna_3-1757410978128.png

so if select app value it check the choice 1 value and it show and it check Choice 2 to the same app and it's visible ,it check Choice3 to the same app and make visible and mandatory based value. please update below script

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    g_form.setMandatory('choice_one', false);
    g_form.setDisplay('choice_one', true);
    g_form.setMandatory('choice_two', false);
    g_form.setDisplay('choice_two', true);
    g_form.setMandatory('choice_three', false);
    g_form.setDisplay('choice_three', true);
    var ga = new GlideAjax('Globalutils');
    ga.addParam('sysparm_name', 'getchoices');
    ga.addParam('sysparm_appname', newValue);
    ga.getXML(mandateChoices);
    //Type appropriate comment here, and begin script below

}

function mandateChoices(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    var json = JSON.parse(answer);
    if (json.appChoice1 == 'true') {
        g_form.setMandatory('choice_one', true);
    } else {
        g_form.setMandatory('choice_one', false);
        g_form.setDisplay('choice_one', false);
        g_form.setMandatory('choice_two', false);
        g_form.setDisplay('choice_two', false);
        g_form.setMandatory('choice_three', false);
        g_form.setDisplay('choice_three', false);

    }
    //  
    //   if(json.appChoice2 == 'true'){
    //  g_form.setMandatory('choice_two', true);
    //   }else{
    //  g_form.setDisplay('choice_two',false);
    //   }
    //   if(json.appChoice3 == 'true'){
    //  g_form.setMandatory('choice_three', true);
    //   }else{
    //  g_form.setDisplay('choice_three',false);
    //   }
}

 

 

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Manohararuna 

so what's not working?

what debugging did you do?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

here the problem is  Choice3 depending on choice2 ,choice2 depending on the choice1 

the above script not working as expected -like below 

because of the above script even after having the value also not making mandatory

Manohararuna_0-1757419447117.png