Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to delete Schedule Event

chanikya
Kilo Sage

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

If you want I can take a look at your dev instance. just give me login info.

dev49569

ray.srock / 123

 in please of Email id  just enter your gamil_id in user profile , and check it please

Mike Patel
Tera Sage

Basically you need to delete existing events before you create new. So add below before your create event script

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.orderBy("sys_created_on");
gr.query();
while(gr.next()){
	gr.deleteRecord();
}

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

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);