Log entire object (unwrap nested JSON)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-19-2022 04:15 PM
I am designing a catalog item and would like to know what the entire object of "current" looks like. Right now, I am using
gs.info(JSON.stringify(current));
However, the result would look something like this
{
...
"variables": {
"a": {},
"b": {},
"c": {},
},
...
}
I am very sure those objects are not empty as I can dot walk through them. However, is there a way to unwrap all the objects and let gs.info display everything? Thanks!
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-19-2022 05:56 PM
One option to see this data is to use something like ServiceNow's script debugger. Otherwise, consulting the documentation for GlideRecord, GlideElement, and GlideElementVariable will help you understand the available methods/properties of each of the types. Example of debugger tree view:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-19-2022 07:15 PM
Steve,
The problem may be that the values aren't being set. This happens in ServiceNow's script arrays. ServiceNow is using Rhino to emulate JavaScript on Java. It seems to have problem when non-String objects are pushed to an array. To add an object to an array, it is necessary to explicitly convert an object to a String. It is also recommended to use .getValue() to get value of an object in GlideRecord.
e.g.
var arr = [];
while (gr.next()) {
arr.push(gr.getValue('name').toString());
}
gs.info(JSON.stringify(arr));