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 michelek87,



Sorry but not received feedback from SN about that.


I've used the workaround which is to create another variable with required options and play with catalog UI policies to display the variable needed.


I've not tried yet below solution proposed by nickbuhl, maybe this will solve the problem, to be tested...


Hi Michele,



Have you been able to find a solution to this problem?.



I am encountering the same problem in Jakarta and even the workaround described by Nickbuhl is not working.


Any help will be appreciated.



Victor Olufowobi


tkaneko
Giga Contributor

My original intent is to run this script on the Catalog Tasks.   I did some more testing and this is what I found out.


By creating a simple catalog item with one select box variable, three options, and a client script that removes one of the options the client script works successfully on the Catalog Item View but DOES NOT work successfully on the Requested Items nor Catalog Tasks.



g_form.clearOptions and g_form.addOption works succesfully for Catalog Item View, Requested Items, and Catalog Tasks so I am thinking there is a bug with removeOption.


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;   


tkaneko
Giga Contributor

Thanks for the input Nick.   your solution is a good workaround and after speaking to HI I learned there are a couple of undocumented functions that will also work as well.



Instead of using g_form.removeOption() you can use g_sc_form.removeOption() which is essentially what your code is doing programatically so at least there are a couple workarounds depending on people's preference.