g_form removeOption does not work on catalog variable

tkaneko
Giga Contributor

I am trying to remove an option from a select box on a catalog variable but it does not remove. The script is:

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

    if (isLoading) {

          return;

    }

  g_form.removeOption('eai_reviewer_sel_next_task', 'eai_research');

  //g_form.clearOptions('eai_reviewer_sel_next_task');

  //g_form.addOption('eai_reviewer_sel_next_task', 'uat_implement', 'UAT Implementation');

  //g_form.addOption('eai_reviewer_sel_next_task', 'prod_implement', 'PROD Implementation');

}

The g_form.clearOptions and g_form.addOption functions seem to work fine but the g_form.removeOption does not.   I would prefer to not clear all options and add back the ones I need as I need to include the 'none' option and its setMandatory properties.

1 ACCEPTED SOLUTION

nickbuhl
Tera Contributor

In case you are still having this problem or someone else stumbles upon this, I was having a similar problem with getControl(), clearOptions() and removeOption() not running on Catalog Tasks or Requested Items when I found this article.


ServiceNow KB: The g_form.getControl method does not work after ordering (KB0547171)


I added the suggested code below to my client scripts and used form.removeOption instead of g_form.removeOption.


var form = typeof g_sc_form != "undefined" ? g_sc_form : g_form;   


View solution in original post

30 REPLIES 30

Hi,



I tried in Geneva and Helsinki its working fine.


Hichem
Mega Expert

Here is the catalog variable :
1.jpg
And here the catalog client script :


2.jpg



What can be double checked more than that ?


Dang!! call Hi support now.


-Anurag

I will do that.
Thanks !


Just wanted to comment on this that there may be several different issues being discussed here:



I think Hichem is talking about the issue that   g_form.clearOption, g_form.addOption and g_form.removeOption (and g_sc_form.removeOption) do not seem to work for a multiple choice variable in the service catalog in Helsinki (I've tested all of them in my Helsinki demo instance and none of them do anything to the multiple choice variable).



Hichem, did you find out anything from SN on this?   I have a client that is using DOM manipulation and of course now in Helsinki it doesn't work and instead of reinforcing bad script I would like to write the script the proper way.