- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2018 10:19 AM
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
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*/
})();
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2018 11:22 AM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2018 01:09 PM
Can you share the code that creates event ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2018 03:34 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2018 05:11 PM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2018 10:13 AM