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

Hichem
Mega Expert

Exactly same issue here !


1 multiple choice variable on a catalog item with 4 question choices.


1 catalog client script on the same catalog item :



function onLoad() {


    g_form.removeOption('myVariablename', 'OneValueOfmyQuestionChoices');


}



but nothing happen...


A workaround is to create another variable with required options and play with catalog UI policies to display the variable needed


What release of ServiceNow?


Hi Chuck,



Tested on FUJI


Alright. Thanks Hichem. Let me see if I can reproduce this. I was testing on Helsinki.


No problem,



Maybe in order to reproduce, you should be aware that I'm using an order guide, and cascading one variable from there to my catalog item (the second screen with tabs) then, the answer to that question will determine if I need to remove options or not.