Group by date/time field

mahive
Kilo Contributor

Hello Everyone,

I have to write a code in which the requirement is to count how many records were created in one particular day.

I have to use the record's created field, and we cannot use Group By in a Date/time field.

So kindly suggest a code to find respective count using Glide Aggregate, by :-

1- First converting the Date/Time as Date.

2. Getting count of record created on one particular date.

 

2 REPLIES 2

Alberto Consonn
ServiceNow Employee
ServiceNow Employee

Hi,

try using the following code as example:

var count = new GlideAggregate('u_check_in');
count.addQuery('sys_created_on', '>', gs.beginningOfYesterday());
count.addAggregate('count');
count.query();
var result = 0;
if (count.next())
  result = count.getAggregate('COUNT');
gs.log('Result: ' + result);

Hope this will be useful for your need!

If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.

Thank you

Cheers
Alberto

Any update on this?

If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.

Thank you

Cheers
Alberto