Log entire object (unwrap nested JSON)

Steve56
ServiceNow Employee
ServiceNow Employee

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!

6 REPLIES 6

Nick Parsons
Mega Sage

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:

find_real_file.png

Hitoshi Ozawa
Giga Sage
Giga Sage

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));