How to use gs.print() method in GLide element
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2016 03:38 AM
Hello ,
We have created one server script and in that we haev userd the gs.print () method.
var count = new GlideAggregate('incident');
count.addQuery('active', 'true');
count.addAggregate('COUNT', 'category');
count.query();
while (count.next()) {
var category = count.category;
var categoryCount = count.getAggregate('COUNT', 'category');
gs.log("The are currently " + categoryCount + " incidents with a category of " + category);
gs.print("The are currently " + categoryCount + " incidents with a category of " + category);
}
We are not able to see the out put.
Please let me know the diffrence between gs.addInfoMessage and gs.print();
Thanks,
Sravanthi.Y

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2016 03:40 AM
gs.addInfoMessage() puts a message on the screen.
gs.print() is visible only if you go to System Diagnostics> Debug Log. Then as your script runs, you will see the messages on the bottom of the screen.
Debugging Tools Best Practices - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2016 03:41 AM
I should have noted, you also used gs.log() which shows up in the system log table. Best practice is to avoid using these in production and it can cause very large log tables, which can slow down your backup (and restore times should you ever require it.) In reality, most people don't use debug statements in production.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2016 03:49 AM
Hi Sravanthi
gs.print() method we use whenever we run a background script to test the output of the script.
gs.addInfoMessage() method shown the result on the servicenow form screen.
Regards
Harsh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2016 03:53 AM
I also encourage you to look at using the scoped debugging API as a more modern approach. gs.print() and gs.log() are not available in scoped applications, whereas gs.debug()/gs.info()/gs.warn()/gs.error() work in scoped or global.
Scoped Script Logging - ServiceNow Wiki