Scheduled job is not triggering event for glideaggregate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2018 10:42 PM
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:
getEventTarget() called with invalid record reference: task_time_worked. for event: deloitte.notification.hours.breached, could have been deleted |
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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2018 12:19 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2018 12:22 PM
Hmm seems like agg isn't a record in the table that is specified in the event registry for "deloitte.notification.hours.breached", can you check that? Also it is probably a good idea to write agg to the log to see if you get the sys_id of a record from that table.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2018 12:22 PM
What do you see in the logs for gs.log ('Deloitte has worked ' + count + ' hours this month');?
var limit = 7; var dur = new GlideDuration(60 * 60 * limit * 1000);
I think you need to covert it to duration before comparing
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2018 08:34 PM
Please see attached on what I see in the logs.
Can anyone confirm that GlideAggregate works for triggering events?
I've also added the open brace as sanh advised but still getting the same error
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 gr = new GlideRecord('u_time_in_hours');
var limit = '7';
if(count>limit){
gs.log ('Deloitte has worked ' + count + agg + ' hours this month');
gs.eventQueue ('deloitte.notification.hours.breached', agg, '', '');
//gs.print(count);
}