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:29 PM
Hi Steve,
Try using JSUtil.logObject().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-19-2022 09:42 PM
It will just print (
Log Object GlideRecord('sc_req_item') @ RITM0708568 |

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-19-2022 10:28 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-19-2022 10:32 PM
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);
}
}
}