From within a ServiceNow script, I am trying to detect whether or not something is defined.
On this page it says
All values are truthy unless they are defined as falsy. That is, all values are truthy except false, 0, -0, 0n, "", null, undefined, and NaN.
Thus, any JavaScript object must be true unless it is null.
Yet consider this ServiceNow code which prints some information about an Incident that was created by a Record Producer which had a variable named location
.
var incGR = new GlideRecord('incident');
incGR.get('49eab040975d6510378377500153afe8');
gs.info(typeof incGR.variables);
gs.info(incGR.variables ? true : false);
gs.info(incGR.variables.location);
gs.info(incGR.variables.constructor.name);
When run as a background script, it prints the following:
*** Script: object
*** Script: false
*** Script: 8269b993db7d3200860930cf9d961945
*** Script: GlideElementVariables
Now I understand that incGR
and incGR.variables
are actually Java objects (created in an old version of the Rhino engine). Still, how can incGR.variables
be false if it is a non-empty object?