Error: “sc_req_item_stageGetChoices” is not defined.

A few days ago I found a really weird bug while I was writing a small application in ServiceNow. I noticed following warning in logs:

org.mozilla.javascript.EcmaError: "sc_req_item_stageGetChoices" is not defined.
Caused by error in sys_script_include.0236e5eddbd22300b5919fd2ca9619c2.script at line 223


After investigation, I found what was generating this error. And it occurred that the bug was being caused by trying to get display value of ‘stage‘ field from service request item within a scoped application. If you try to execute the following code in scope you will get the same result:

var sc = new GlideRecord('sc_req_item');
sc.setLimit(1);
sc.query();
sc.next();

gs.info(sc.stage.getDisplayValue());

The output is:

Evaluator: org.mozilla.javascript.EcmaError: "sc_req_item_stageGetChoices" is not defined.
   Caused by error in script at line 1

==>   1: var sc = new GlideRecord('sc_req_item');
      2: sc.setLimit(1);
      3: sc.query();
      4: sc.next();

Evaluator: org.mozilla.javascript.EcmaError: "sc_req_item_stageGetChoices" is not defined.
   Caused by error in script at line 6

      3: sc.query();
      4: sc.next();
      5: 
==>   6: gs.info(sc.stage.getDisplayValue());

But if you use the different field, which is not a type of ‘Workflow’ (‘state’ for instance), it will work fine:

var sc = new GlideRecord('sc_req_item');
sc.setLimit(1);
sc.query();
sc.next();

gs.info(sc.state.getDisplayValue());

x_75712_test: Open

‘Try catch’ is not very helpul:

var sc = new GlideRecord('sc_req_item');
sc.setLimit(1);
sc.query();
sc.next();

try{
	gs.info(sc.stage.getDisplayValue());
}catch(ex){
	gs.error(ex);
}

Evaluator: org.mozilla.javascript.EcmaError: "sc_req_item_stageGetChoices" is not defined.
   Caused by error in script at line 1

==>   1: var sc = new GlideRecord('sc_req_item');
      2: sc.setLimit(1);
      3: sc.query();
      4: sc.next();

Evaluator: org.mozilla.javascript.EcmaError: "sc_req_item_stageGetChoices" is not defined.
   Caused by error in script at line 7

      4: sc.next();
      5: 
      6: try{
==>   7: 	gs.info(sc.stage.getDisplayValue());
      8: }catch(ex){
      9: 	gs.error(ex);
     10: }

x_75712_test: fulfillment

Fortunately in my case getting this value from GlideRecord was enough to meet requirements:

var sc = new GlideRecord('sc_req_item');
sc.setLimit(1);
sc.query();
sc.next();

gs.info(sc.getValue('stage'));

x_75712_test: fulfillment

Leave a Reply

Your email address will not be published. Required fields are marked *