Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to log an Object in ServiceNow?

Meloper
Kilo Sage
var Arrays = Class.create();
Arrays.prototype = Object.extendsObject(AbstractAjaxProcessor, {


    diffArrays: function(a1, a2) {

        var a = [],
            diff = [];
        var oldBigger = false;

        for (var i = 0; i < a1.length; i++) {
            a[a1[i]] = true;
        }
        gs.log('1a ' + JSON.stringify(a));
        gs.log('2a ' + a);
        gs.print('3a' + JSUtil.logObject(a));
		        gs.print('4a' + JSUtil.describeObject(a, 'name'));

		
        gs.log(global.JSON().encode(a))

        for (var i = 0; i < a2.length; i++) {
            if (a[a2[i]]) {
                delete a[a2[i]];
            } else {
                a[a2[i]] = true;
            }
        }

        for (var k in a) {
            gs.log('5a ' + k);

            diff.push(k);
        }

        if (a1 < a2) {
            oldBigger = true;
        }

        return [diff, oldBigger];
    },
    type: "Arrays"

});
var test = new Arrays();
gs.log(test.diffArrays(["a", "b", "d"], ["a", "b", "c"]));
var array123 = [1, 2, true]

 

LOG:

32 REPLIES 32

yes, no Output

Hi,

your function parameter for a is a1 so you need to use that for printing within function

gs.info(a1.toString());

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Meloper 

Hope you are doing good.

Did my reply answer your question?

Would you mind marking the best matching answer as correct and helpful, to close this thread?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Meloper 

Hope you are doing good.

Did my reply answer your question?

If my response helped you please mark it correct to close the question so that it benefits future readers as well.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Brad Tilton
ServiceNow Employee
ServiceNow Employee

You can log an object with JSUtil.logObject or you could just do a JSON.stringify of the object and log it.