How to log an Object in ServiceNow?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2021 06:04 AM
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2021 06:18 AM
Please look teh code after the first for loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2021 06:25 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2021 06:27 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2021 06:37 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2021 06:37 AM
the script is working fine. The Results are great
