Question

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"

Was it helpful?

Solution

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());
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top