How to delete Schedule Event

chanikya
Tera Guru

Hi,

For example, if the Alert Due Date was originally set on the HR Form  Request for 10:04:00AM on 27/04/2018 and the form is submitted, an Event is logged and sits in the 'Ready' state until that time. If the Alert Due Date  is then changed to 10:06:00AM on 27/04/2018, a new Event is created, but the old one stays in the Event queue. Basically, the user will end up getting two emails, one at 10:04:00AM and one at 10:06:00AM.

 still it is triggered two times , why it was happend

 

find_real_file.png

find_real_file.png

To delete old Event queue i have written B.Rule script,, To retrieve this  B.Rule script was written here, by using this it is not creating any mail triggers at least one time too......

BR: Update, after 

Table : u_hr_form

Condition:current.u_alert_due.changes()

(function () {

// Add your code here
var gr = new GlideRecord('sysevent'); // We need to query the sysevent table
gr.addQuery('state', 'ready'); // We only want the event in the ready state
gr.addQuery('name', 'alert_due'); // Change the event name to the event name you are using
gr.addQuery('table', 'u_hr_form');
gr.addQuery('instance', current.sys_id + ''); // Get the event that has been created for this record
gr.setLimit(1); // Assuming there is only one ready event active for this record at a time, this can improve performance
gr.deleteMultiple();
/* Schedule your new event here*/

})();

 

find_real_file.png

 

1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

So 2 business rule 1 on insert and 2nd for update

Insert

(function executeRule(current, previous /*null when async*/) {
gs.eventQueueScheduled('alert_due',current,current.u_approver,'',current.u_alert_due);
})(current, previous);

 

Update

Alert due changes

(function executeRule(current, previous /*null when async*/) {

// Add your code here
var gr = new GlideRecord('sysevent');
gr.addQuery('state', 'ready'); // We only want the event in the ready state
gr.addQuery('name', 'alert_due'); // Change the event name to the event name you are using
gr.addQuery('table', 'u_hr_form');
gr.addQuery('instance', current.sys_id); // Get the event that has been created for this record
gr.query();
while(gr.next()){
gr.deleteRecord();
}

gs.eventQueueScheduled('alert_due',current,current.u_approver,'',current.u_alert_due);

})(current, previous);

View solution in original post

10 REPLIES 10

Mike Patel
Tera Sage

Can you share the code that creates event ?

Thanks for your reply,

creates event: 

BR script: Before,   update,insert

Table: u_hr_form, 

 gs.eventQueueScheduled('alert_due',current,current.u_approver,'',current.u_alert_due);

 

it is creating event even  on create new one records , when i updated existed records...........

So now, what i have to do here...............please guide me step wise please

Add condition like current.alert_due.changes() to creates event business rule

change script to 

 

var gr = new GlideRecord('sysevent'); 
gr.addQuery('state', 'ready'); // We only want the event in the ready state
gr.addQuery('name', 'alert_due'); // Change the event name to the event name you are using
gr.addQuery('table', 'u_hr_form');
gr.addQuery('instance', current.sys_id); // Get the event that has been created for this record
gr.query();
while(gr.next()){
	gr.deleteRecord();
}

gs.eventQueueScheduled('alert_due',current,current.u_approver,'',current.u_alert_due);

not working...........

still it is triggering 2-times of notifications...

 

find_real_file.png