Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Log entire object (unwrap nested JSON)

Steve56
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

It will just print (

My bad. I misunderstood the question.

JSON.stringify() will convert json to a string but this isn't want is desired.

To dump content of the "current" as is used in business rule variable, there's a need to iterate through.

In business rule, current and previous is probably a GlideRecord.

Haven't tested but something like calling function like below.

function dump(obj) {
    var fields = obj.getFields();

    // Enumerate GlideElements in the GlideRecord object that have values
    gs.print('Enumerating over all fields with values:');
    for (var i = 0; i < fields.size(); i++) {
        var glideElement = fields.get(i);
        if (glideElement.hasValue()) {
            gs.print('  ' + glideElement.getName() + '\t' + glideElement);
        }
    }
}

https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server_legacy/c_GlideRecordAPI#r_Gl...