How to use gs.print() method in GLide element

ycs1
Kilo Contributor

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

4 REPLIES 4

Chuck Tomasi
Tera Patron

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


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.


HarshTimes
Tera Guru

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


Chuck Tomasi
Tera Patron

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