gs.eventqueue triggers event but state is error

ankitsharma_487
Giga Guru

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

 

1 ACCEPTED SOLUTION

ankitsharma_487
Giga Guru

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

View solution in original post

18 REPLIES 18

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!

Community Alums
Not applicable

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

 

Community Alums
Not applicable

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

 

 

Rajesh Chopade1
Mega Sage

Hi @ankitsharma_487 

 

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 Type Description
nameStringName of the event being queued.
glideRecordObjectGlideRecord object, such as "current".
parm1String(Optional) Saved with the instance if specified.
parm2String(Optional) Saved with the instance if specified.
queueStringName 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,

-O-
Kilo Patron
Kilo Patron

Can you show the definition of event "send_approval_reminder"?