Notification triggered by event multiple times

Kasia5
Tera Contributor

Hi All,

 

I have a notification which is triggered by event but it looks like sth is wrong cause when conditions are met then notification is send multiple times.. I mean even more than 100 hundred during 1 minute..

 

Event:

Kasia5_0-1678700647032.png

 

Business rule:

Kasia5_1-1678700677868.png

Kasia5_0-1678700817084.png

 

(function executeRule(current, previous /*null when async*/ ) {

var rq = new GlideRecord("sc_req_item");
rq.addEncodedQuery('state=1^ORstate=2^ORstate=-5');
rq.query();
while (rq.next()) {
var ga = current.updated_by;
var gp = new GlideRecord("sys_user");
gp.addQuery('user', ga);
gp.query();
while (gp.next()) {
var gt = gp.getValue("user_name");
if (gt.contains('xyz')) {
gs.eventQueue('sc_task.updated_by', current, current.number, gs.getUserName());
}
}
}
})(current, previous);

 

What can be wrong?

 

Thanks in advance for help!

2 REPLIES 2

AnveshKumar M
Tera Sage
Tera Sage

Hi @Kasia5 ,

 

You need to revisit the logic here, while querying sc_req_item (Request Item) table, you are querying all the Request Item records filtered on states (1, 2 and 5). So all the request items are fetched and the event is triggering for every request item. 

 

I assume that, you want to fetch the parent Request Item of the catalog task only. If yes, use the following code in business rule.

 

....
....
var rq = new GlideRecord("sc_req_item");
//Add below line
rq.addQuery('sys_id', current.request_item);
rq.addEncodedQuery('state=1^ORstate=2^ORstate=-5');
rq.query();
....
...

 

Try with the above code, It should resolve the multiple event triggers.

 

And I found other issues in your script, which is out of current question scope. First fix the multiple event triggers using above code and let me know if anything else is missing to achieve your requirement.

 

Thanks,

Anvesh

Thanks,
Anvesh

Thanks!

I've tried with add above code but it looks there is still the same issue