How to trigger an event by Schedule Job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 09:53 AM
Hello guys!
I have a problem with the eventQueue, it is not triggering the notification and the event is not starting.
Schedule Job:
All conditions are being met, I did the test and everything passed (there was more "gs.info" in the code).
Event:
Do not know whether the need to put the table. But I saw another example of Schedule Job with eventQueu, which event had no table selected.
Notification > When to send:
Notification > Who will receive:
Please, if anyone can help me, I'm out of time to deliver this story!
Thank you very much!
TABLE: ast_contract
SCRIPT:
var gd = new GlideDate();
gd.addDays(-365);
var gr = new GlideRecord('ast_contract');
gr.addQuery('state', '=', 'active');
gr.addQuery('u_contract_term', '=', '2_years');
gr.query();
while (gr.next()) {
gs.info(gr.number);
var startDate = gr.starts;
gs.info("startdate" + startDate);
if (startDate == gd) {
gs.info('Entrou if startDate!');
gs.eventQueue('ipca.changed', 'gr', '');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 10:03 AM - edited 12-14-2022 10:05 AM
gs.eventQueue('event_name'); runs with single parameter also.
Also you have passed gr in quotes, it is a variable so should be without quotes in gs.eventQueue('event_name',gr);
You need to make sure below:
1. You are getting in if condition.
2. Your event name is correct.
3. Check event logs ( by name). There should be a entry for your event.
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 10:06 AM
I tested it with eventQueue('event_name', ' ', ' ', ' ') and it didn't work either.
There's a gs info after the If, so yes, it's going into the If.
Event name is correct.
I checked the event log and my event doesn't appear.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 10:08 AM
Pass gr without quotes as below:
gs.eventQueue('event_name',gr);
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 10:05 AM - edited 12-14-2022 10:12 AM
Modified gs.eventQueue() statement a bit. Also pass the recipient or recipents list in the parameter of this statement as per your need. Also try once without if statement, you might have to compare dates in a different way.
var gd = new GlideDate();
gd.addDays(-365);
var gr = new GlideRecord('ast_contract');
gr.addQuery('state', '=', 'active');
gr.addQuery('u_contract_term', '=', '2_years');
gr.query();
while (gr.next()) {
gs.info(gr.number);
var startDate = gr.starts;
gs.info("startdate" + startDate);
if (startDate == gd) {
gs.info('Entrou if startDate!');
gs.eventQueue('ipca.changed', gr, '');
}
}
Refer to below link for better understanding of eventQueue.
eventQueue(String name, Object glideRecord, String parm1, String parm2, String queue)