The CreatorCon Call for Content is officially open! Get started here.

Email notification if change task 7 days past due date!

karanchawla2002
Kilo Explorer

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

Please help!

1 ACCEPTED SOLUTION

I don't think you're actually looping through the records you found in your example, so gr is referencing a set of records. Try this:



var gr = new GlideRecord('change_task');


gr.addQuery('due_date', '<=', gs.nowDateTime());


gr.addQuery('active', true); //you probably want to add this so you only send reminders on open tasks


gr.query();


while (gr.next()) {


    gs.eventQueue("change_task.duedate_reminder", gr, gs.getUserID(), gs.userName());


}


View solution in original post

11 REPLIES 11

By the way this is the error log message



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


I don't think you're actually looping through the records you found in your example, so gr is referencing a set of records. Try this:



var gr = new GlideRecord('change_task');


gr.addQuery('due_date', '<=', gs.nowDateTime());


gr.addQuery('active', true); //you probably want to add this so you only send reminders on open tasks


gr.query();


while (gr.next()) {


    gs.eventQueue("change_task.duedate_reminder", gr, gs.getUserID(), gs.userName());


}


Thank You ...You were right!!


Brad,



Quick question about this.   My assumption is that the gs.eventQueue refers to the table email template and not the email notification, correct?



I have not been able to get the scheduled script to run, see below, maybe I am missing something:


var gr = new GlideRecord('cmdb_ci_spkg');  


gr.addQuery('u_term_note_date', '<=', gs.nowDateTime());   // compare notice date and current date


gr.query();  


while (gr.next()) {  


    gs.eventQueue("cmdb_ci_spkg.license_reminder");   // set email via license_reminder template


}  


Hi Wade,



gs.eventQueue() fires an event. You have to also have registered the event and set up an email notification to respond to the event. In your case, you also need to pass a second argument there, which would typically be your gr object like this:



gs.eventQueue("cmdb_ci_spkg.license_reminder", gr, gs.getUserID());




I always pass a userid as well out of habit.