Make Mandatory variable set variables based on variable choice

kotab
Tera Contributor

Hi All 
i have requirement based on variable choice want to make variable set  variables mandatory. I configure below on change script but not working please review below script and help me with correct solution 

   var variableNames = [
        'cost_code'.........
    ];
    var makeMandatory = (newValue == 'Azure');
    variableNames.forEach(function(varName) {
        g_form.setMandatory(varName, makeMandatory);
    });
}
2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@kotab 

can you share the complete script?

are you sure you are giving the correct variable names?

any other UI policy is conflicting?

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

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var variableNames = [
        'cost_code'.............
    ];
    var makeMandatory = (newValue == 'Azure');

    // Loop through each variable and set it as mandatory or not
    variableNames.forEach(function(varName) {
        g_form.setMandatory(varName, makeMandatory);
    });
}
FYI : i took correct variable
No UI policy