- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2023 08:42 AM
Below is the code which triggers event but event's state turns to ERROR, please find screenshot also
var gr = new GlideAggregate("sysapproval_approver");
gr.addQuery("state", "requested");
gr.addAggregate("COUNT", "approver");
gr.query();
while(gr.next()){
gs.eventQueue("send_approval_reminder",gr, gr.approver, gr.approver.getDisplayValue());
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2023 10:08 AM
Hey guys, thanks all for your help and putting time into it, I was able to figure out this
I stored approver sys ids into an array and then looped it for triggering email.
That Worked

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2023 09:37 AM - edited ‎03-09-2023 09:43 AM
Hello,
Your script you provided is getting the count, you didn't group by anything, and when you used the count, you weren't even using the count in your final script anyway. So we wouldn't know what you were trying to do because using GlideAggregate but adding in "Count" to it, didn't unique anything.
Either way, you can't use GlideAggregate with firing events. It doesn't work. You'd have to use GlideRecord.
You can refer to this article for ideas on how to use it with GlideRecord: https://www.servicenow.com/community/now-platform-articles/one-daily-email-reminder-that-contains-al...
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2023 09:39 AM - edited ‎03-09-2023 09:48 AM
Ok, I understand.
Then you must get the mentioned records - try:
var gr = new GlideAggregate("sysapproval_approver");
gr.addAggregate("COUNT");
gr.orderByAggregate("COUNT");
gr.groupBy("approver");
gr.query();
while(gr.next()){
var currentGR = gr;
var currentApprover = gr.approver;
var currentApproverDV = gr.approver.name;
gs.eventQueue("send_approval_reminder", currentGR, currentApprover, currentApproverDV);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2023 09:05 AM - edited ‎03-09-2023 09:09 AM
Can you test with:
btw - using GlideAggragate() is not suitable here - you dont need total count, you need just to fire event. Better use GlideRecord.
var gr = new GlideAggregate("sysapproval_approver");
gr.addQuery("state", "requested");
gr.addAggregate("COUNT", "approver");
gr.query();
while(gr.next()){
var currentGR = gr;
var currentApprover = gr.approver;
var currentApproverDV = gr.approver.name;
gs.eventQueue("send_approval_reminder", currentGR, currentApprover, currentApproverDV);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2023 09:09 AM
gs.eventqueue is used to trigger an event.This is used in server side.
eventQueue(String name, Object glideRecord, String parm1, String parm2, String queue)
Parameter(s):
name | String | Name of the event being queued. |
glideRecord | Object | GlideRecord object, such as "current". |
parm1 | String | (Optional) Saved with the instance if specified. |
parm2 | String | (Optional) Saved with the instance if specified. |
queue | String | Name of the queue. |
The first parameter is event name and this is defined in the event-> Registry.
In your case you have used 'GlideAggregate' object could you try once with replacing with GlideRecord.
Please mark your response helpful or correct.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2023 09:35 AM
Can you show the definition of event "send_approval_reminder"?