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:08 AM
Hi,
What do you wish to print exactly?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2021 06:17 AM
It is a pity that no line numbers are displayed.
I want to log "a" after the first for loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2021 06:23 AM
from the script I believe you want difference between 2 arrays
then why not use OOB ArrayUtil diff method
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2021 06:28 AM
1. i want to log Object "a" in that script at that "place" the script is just a example?
2. What Diff Method?
