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

Please look teh code after the first for loop

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Ahh ok, I'll admit I just read the question and not the code. Could you describe the results you're looking for here and where you're experiencing an issue?

i guess the lof should show

"a" = true,

"b" = true,

"c" = true,

 

Because all Elements of the first Array A1 is written in a, in the first loop

 

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I think your issue has to do with your for loop where you're not actually populating a with anything as the array is still empty after the loop.

I would agree with Ankur that you should try using ArrayUtils for this.

the script is working fine. The Results are great