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

ankitsharma_487_0-1678383601967.png

 

-O-
Kilo Patron
Kilo Patron

Could you provide one more information?

Does column Instance of those event records contain anything - I expect it is empty (because GlideAggregate).

yes , thats empty

That is most likely the problem here: something reacting to the event is trying to reconstitute the record, but it will fail as it has no sys_id to go with.

Try modifying the event definition to point to the User table instead.

At the same time fetch the user record in the script and use that as 2nd parameter to gs.eventQueue().

Something like:

 

var gr = new GlideAggregate("sysapproval_approver");

gr.addQuery("state", "requested");
gr.addAggregate("COUNT", "approver");
gr.query();

while (gr.next())
	notifyUser('' + gr.approver);

function notifyUser (uniqueValue) {
	var sys_user = new GlideRecord('sys_user');

	if (sys_user.get(uniqueValue))
		gs.eventQueue("send_approval_reminder", sys_user, sys_user, sys_user.getDisplayValue());
}

 

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