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

Hi,

refer this class

ArrayUtil

find_real_file.png

Regards
Ankur

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

yes thanks, but this is not the Question, i want to Print a after the loop

Hi,

it is plain array so just use this to print it

gs.info(a.toString());

Regards
Ankur

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

i guess it is an SNOW related Problem.

In Vanilla JS i can log the object.

Hi Ankur, my Array Util looks like that:

i call it with this:

Do you know why it return an undefined?

Why does the Scirpt include function does not have parameters?

The Util is not overwritten, last update on 2018 by admin(Servicennow) so it is the oob.