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

Allen Andreas
Administrator
Administrator

Hi,

Is there a reason you're using GlideAggregate for this?

I'd recommend switching to GlideRecord API instead and removing the count addAggregate because you're not using it anyway?


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

ankitsharma_487
Giga Guru

The scenarios is- I have to get unique entries of approvers who have approvals pending 

Hi @ankitsharma_487 

Well, you are, by looking at the state and seeing that it's requested.

So it will only return records in that state and you're while looping through them and firing an event for each one.

And as you see below, they're mentioning the same thing I did above, you'd need to use GlideRecord for this.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

I may be not understanding your solution but let say there are 10 approvals pending for user1 and 100 for user2
if I use GlideRecord it will trigger total 110 event and they will generate separate notification which will spam user

if I get unique value somehow(for same I am using glideaggregate) which will return only 2 events