- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 06:04 AM
I often see code like this
var debug = true;
if (debug) gs.print(msg);
if (debug) gs.info(msg);
Is there a specific reason why people don't use the GlideSystem instead? Like this
if (gs.isDebugging()) gs.print(msg);
Or maybe even shorter
gs.debug(msg);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 06:12 AM
FWIW, I often have distinct debugging in each of my script includes so I can debug them independent of each other (not get overwhelmed with debug output.) In those cases, I'll make an _debug function.
_debug : function(msg) {
if (this.debug)
gs.debug(msg);
}
Then call it in various places as
this._debug(recordCount + ' records read');
I can then turn on and off the debug property in the script include with a property so I don't have to modify code in production to enable/disable debugging.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 06:09 AM
Hi Peter,
This should help for global scope or legacy apps not in a scope.
Debugging Tools Best Practices - ServiceNow Wiki
Although it is starting to become a bit dated as it does not yet include scoped applications. For scoped apps, gs.print() and gs.log() are not available. For those, the new API is gs.debug/info/warn/error. And you can set the destination and verbosity per application which makes it very useful to debug.
Scoped Script Logging - ServiceNow Wiki
There is no gs.isDebugging() method.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 06:14 AM
Thanks. I will be glad to read through them. It does surprise me that people keep linking to the old Fuji documentation.
PS: gs.isDebugging exists. It is mentioned in your second link and here is the official documentation on the (scoped) function ServiceNow Developers - gs.isDebugging()

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 06:18 AM
Thanks for the education. I didn't know about gs.isDebugging(). #oldtimer It must have come out in Geneva. Sadly, the documentation doesn't say what it is predicated on. What turns debugging on/off? Is it the scoped properties scope.logging.verbosity and scope.logging.destination?
I'll ask and find out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 06:23 AM
To answer your question, I'll quote your own link
The following method is available for determining if debug is active, returning true when either session debugging is active or log verbosity is set to debug for the current application:
gs.isDebugging()