We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Mohit Kaushik
Mega Sage

Hi Everyone,

I am planning to start a weekly dose of ServiceNow features in Washington DC release. Please add your comments and let me know if I am missing anything.

 

Week 1: setIntervalYearIncluded()

With Washington DC release, ServiceNow brought a new GlideAggrigate API method "setIntervalYearIncluded()" for scoped and global applications.

This method lets you decide whether to group results by year for day-of-week trends or not. These trends can be created by using addTrend() method with dayofweek time interval. It is a Boolean type method and with the parameters as true or false you can either group the results by year or exclude it respectively in your result. By default, the result with addTrend() shows the year in the trend along with the day of week.

Sample script to display the count of incident records separated by the day of week without including the year.

var incGr = new GlideAggregate('incident');
incGr.addTrend('sys_created_on','dayofweek');
incGr.addAggregate('COUNT');
incGr.setIntervalYearIncluded(false);
incGr.query();
while(incGr.next()){
gs.info(incGr.getValue('timeref')+': '+incGr.getAggregate('COUNT'));
}


Output:

MohitKaushik_0-1716995231076.png

 


Note: It will only work with day-of-week trend. You can find the official documentation here.

 

Regards,

Mohit Kaushik

2XServiceNow MVP (2023-2024)