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.

clearoptions() and removeoptions() not working

amaradiswamy
Kilo Sage

Hi All,

Based on the conditions, i need to add/remove options from the choice data type fields. I have written 2 scripts. one script is working as expected but in second script it is not clearing the options eventhough it is going into the loop( i have checked by using alert). And i have checked all the field names and choice values.

What could be the possible reason for this behaviour and how to fix this issue?

Thanks and regards,

Swamy

9 REPLIES 9

xiaix
Tera Guru

Please share your 2 scripts so that we can see what may be happening.


Hi David,



Thanks for you reply.



script which is working: i have writen on state field



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


    if (newValue == '') {


          return;


    }




    //Type appropriate comment here, and begin script below


  if(newValue != '1')// choice value of deployed is 1


  {


  g_form.clearOptions('u_abc');




          }


  else


  {




  if(newValue == '1')


  {


  //g_form.addOption('u_usage_type', '-- None --', '-- None --');


  g_form.addOption('u_abc', 'Dedicated', 'Dedicated');



}



  if(newValue != '1')


  {


  g_form.setValue('u_abc','');


  }


}


}


Script which is not working:


function onChange(control, oldValue, newValue, isLoading, isTemplate) {


    if ( newValue == '') {


          return;


    }



  if(newValue == 'abc')


  {




  g_form.clearOptions('u_xyz');



  g_form.clearValue('u_uvw');// clearing is working but options are still visible





  }


  else


  {



                      g_form.clearOptions('u_xyz');


  g_form.addOption('u_xyz', '--None--', '--None--');


  g_form.addOption('u_xyz', 'Active', 'Active');



}


  if(newValue == 'Owned')


  {


  g_form.setValue('u_xyz','');


  }



          }



Regards,


Swamy


Options will be visible, if you want to clear the options as well then use ClearOptions functionin the script, You are just clearing the value specified on that field.


Oh.. actually i mean the script is clearing the values in u_uvw but it is not clearing the options in u_xyz field eventhough i have used clearOptions() function.



Regards,


Swamy