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


I have quite the same problem, but in the Record Producer


I have defined a variable named "operating_system" [it is a multiple choice variable], that contain 5 possible values.




Now, from the Catalog UI Policy I have defined one rule that are triggered the following code:



function onCondition() {


        // g_form.removeOption('operating_system', 'linux');


        // g_form.removeOption('operating_system', 'android');


        // g_form.removeOption('operating_system', 'ios');


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


        form.removeOption('operating_system', 'linux');


        form.removeOption('operating_system', 'android');


        form.removeOption('operating_system', 'ios');


}



but this dont't work and I can't undestand why ... I have also modify the g_form variable with the variable "form", defined like indicated in the previsu post.



Can someone identify why this don't work?



Regards


Vincenzo


Community Alums
Not applicable

hi it's not working

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
var form = typeof g_sc_form != "undefined" ? g_sc_form : g_form;

form.removeOption('additional_systems','24');

}

Community Alums
Not applicable

Nothing worked..

g_form.removeOption("cer_type_of_headset", "Duo");

or

var form = typeof g_sc_form != "undefined" ? g_sc_form : g_form;    
form.removeOption("cer_type_of_headset", "Duo");

or

g_sc_form.removeOption("cer_type_of_headset", "Duo");

Joe Taylor
Giga Guru

Has anyone been able to get the g_form.remove.Option method to work on Catalog items yet?

I was told this was due to an "order of execution" error in Orlando Patch 1 and earlier.

SNOW said this was supposed to be addressed in Orlando Patch 2.

We are now on Orlando Patch 4 and I still can't get this to work.

jackinsidend
Giga Guru

It works but you need to use the full set of parameters:

g_form.addOption('priority', '6', '6 - Really Low');

g_form.removeOption('priority', '6', '6 - Really Low');

If you just use the value, it does not work.

Jack