logo

NJP

ServiceNow Things to Know 122: new method in GlideAggregate

Import · May 20, 2024 · article

Hello Everyone,

There is an additional method available in the GlideAggregate class in the Washington DC release. It groups results by year for day-of-week trends. These trends are created using the addTrend() method with the dayofweek time interval.

Script:

var incidentGroup = new GlideAggregate('incident');

incidentGroup.addTrend('sys_created_on', 'dayofweek');

incidentGroup.addAggregate('COUNT');

incidentGroup.setIntervalYearIncluded(false);

incidentGroup.query();

while (incidentGroup.next()) {

gs.info(incidentGroup.getValue('timeref') + ': ' + incidentGroup.getAggregate('COUNT'))};

Output:

[0:00:00.049] Script completed in scope global: script

Script execution history and recovery available here

*** Script: Monday: 8*** Script: Tuesday: 8*** Script: Wednesday: 18*** Script: Thursday: 8*** Script: Friday: 13

*** Script: Saturday: 16

View original source

https://www.servicenow.com/community/developer-blog/servicenow-things-to-know-122-new-method-in-glideaggregate/ba-p/2936153