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

Brad Bowman
Kilo Patron
Kilo Patron

You'll need a similar script onLoad to only show the choices for the value of Category after the record is saved / when it is loaded.

Paul Curwen
Giga Sage
If you want this to run on form load or after you Save the record, either add similar script to an onLoad Client Script or change your code at the top to: 
 
    if (newValue === '') {
        return;
    }
 
 
***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul

Hi @Paul Curwen  I have tried to create a similar onload client script   but its not working after saving the record I am able to see whistle blower for india location

function onLoad() {
   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');
  }
  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');
  }
}
   

You didn't clearOptions in this script as you did onChange.  Add alerts to confirm the value of loc.  If you clearoptions you don't need any removeoption lines, but if you don't then you don't need any addoption lines - only removeoptions.