ServiceNow Widget Debugging: Temporarily Set Any Field Value (Without Touching Code)
Let’s be honest… Service Portal debugging is slow. Every small change = 👉 Update script 👉 Save 👉 Reload 👉 Navigate back 👉 Test again Repeat that 10 time...
If you're anything like me you must have spent a fairbit of time scratching your head over when to use GlideRecord and when to switch to GlideAggregate. I want to dive into the nitty-gritty of these concepts especially when need of using GlideRecord's getRowCount().
GlideRecord is a ServiceNow API which can be used for all operations on individual database records in ServiceNow, be it querying, updating, or deleting.
var gr = new GlideRecord('incident');
gr.addQuery('priority', 'Critical');
gr.query();
gs.print('Total Critical Incidents: ' + gr.getRowCount());
GlideAggregate is a ServiceNow API specialized for calculations across records. As the name suggests you can aggregate the records and perform opeations like count, sum, average.
var ga = new GlideAggregate('incident');
ga.addQuery('priority', 'Critical');
ga.addAggregate('COUNT');
ga.query();
if(ga.next()) {
gs.print('Total Critical Incidents: ' + ga.getAggregate('COUNT'));
}
While 'getRowCount()' with GlideRecord does the job in getting the count of the result, there is a compelling reason to go for GlideAggregate.
GlideAggregate usually fetches counts faster. With 'getRowCount()', GlideRecord loads all records just to count them. GlideAggregate, on the otherhand, directly retrieves this count ensuring efficiency.
Until next time, happy coding! 💻🚀
Written by
Let’s be honest… Service Portal debugging is slow. Every small change = 👉 Update script 👉 Save 👉 Reload 👉 Navigate back 👉 Test again Repeat that 10 time...
If you’ve worked with Multi-Row Variable Sets (MRVS) in ServiceNow, you’ve probably seen this requirement come up: “Allow users to add rows sometimes… but rest...
Learn how to embed the ServiceNow Virtual Agent in any website using the Portable Web Client, with support for SSO, CORS, and custom branding. Includes code sam...