Clear options and add options not working ?

kiran kumar m1
Tera Contributor

I wrote a onchange client script , if I select India it should show me 3 options if I select Philippines it should show me 4 options, while changing the location field I can see the change like for India its showing 3 options and for Philippines its showing 4 options , but the issue is once I save the ticket for India its showing all the 4 options.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
   
       
        g_form.clearOptions('category');
        var loc = g_form.getDisplayValue('location');
        if ( loc== 'India') {
            g_form.addOption('category', 'Harassment', 'Harassment');
            g_form.addOption('category', 'Retaliation', 'Retaliation');
            g_form.addOption('category', 'Discrimination', 'Discrimination');
            g_form.removeOption('category', 'Whistle Blower', 'Whistle Blower');
        } else if (loc == 'Philippines') {
            g_form.addOption('category', 'Harassment', 'Harassment');
            g_form.addOption('category', 'Retaliation', 'Retaliation');
            g_form.addOption('category', 'Discrimination', 'Discrimination');
            g_form.addOption('category', 'Whistle Blower', 'Whistle Blower');
        }
    }   here is the code . Can anyone tell me what  is the error ? I want a functionality such that even after saving the ticket it should show me only 3 options in category field for India.
5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@kiran kumar m1 

after saving the record your onChange won't run as isLoading will stop that

Did you try adding alert and verify?

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