Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Scheduled job is not triggering event for glideaggregate

pokai
Tera Contributor

I'm new to developing to bear with me.
I am trying to do a daily scheduled job to check the number of hours worked for the current month and if it breaches 7 to trigger an event. I can get the log to come through but the event fails to trigger. Can anyone advise what I did wrong?

Error: 

My scheduled job script is below:

for(var i = 0; i< 1; i++){


var agg = new GlideAggregate('task_time_worked');


agg.addAggregate('sum','u_time_in_hours');


agg.setGroup(false);


agg.addQuery('sys_created_on', '>=', 'javascript:gs.monthsAgoStart('+i+')');


agg.addQuery('sys_created_on', '<=', 'javascript:gs.monthsAgoEnd('+i+')');


agg.query();


var count;


while (agg.next())


count = agg.getAggregate('sum','u_time_in_hours');

var limit = '7';
if(count>limit){
gs.log ('Deloitte has worked ' + count + ' hours this month');
gs.eventQueue ('deloitte.notification.hours.breached', agg, '', '');
//gs.print(count);
}
}

6 REPLIES 6

sanh
Tera Contributor
Do you have a notification created to the respective event?

pokai
Tera Contributor

Yes I do - please see attached.

Normally I have triggered events via script with no issues but I can't seem to get a GlideAggregate one to work.

I'm assuming that it will never work with GlideAggregate