1

I am trying to set up an email notification ONLY IF a change task is past due date! The email should only be sent to the person who has been assigned the change task.

This is what I am doing :

1)This is the script in the scheduled job :

      var gr = new GlideRecord('change_task');
      gr.addQuery('due_date','<=', gs.nowDateTime());
      gr.query();


      var count = gr.getRowCount();
      if (count > 0)
      {
        gs.eventQueue("change_task.duedate_reminder", gr, gs.getUserID(), gs.userName());
      }

2) Created an event in registry named "change_task.duedate_reminder "

3) Created an email notification when the above mentioned event is fired. Used 'aasigned_to' as the recipient!!

This is the error log message:

"getEventTarget() called with invalid record reference.change_task. for event: change_task.duedate_reminder, could have been deleted"

user2475677
  • 149
  • 2
  • 5
  • 11

1 Answers1

2

if count is greater than 0, you need to call gr.next() to load each record in the collection, otherwise, the gr instance you are passing to gs.eventQueue(...) is going to be unpopulated with results (eventQueue only handles a single, populated GlideRecord).

If you're potentially expecting a collection of records, you'll need to iterate them like so:

gr.query();
while (gr.next()){
   gs.eventQueue("change_task.duedate_reminder", gr, gs.getUserID(), gs.userName());
}
Joey
  • 2,901
  • 21
  • 22
  • I'd also add that the current script would end up sending a notification to every single past-due change task every time it's run. If you're wanting it only to send the notification *one time*, you'll need to change your query up a bit to only grab items since the last run of the script. For example, if the script runs once an hour: var gr = new GlideRecord('change_task'); gr.addQuery('due_date','<=', gs.nowDateTime()); gr.addQuery('due_date','>', gs.hoursAgo(1)); gr.query(); – GarrettNow Feb 28 '14 at 18:13