Notification triggered by event multiple times
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 02:46 AM - edited 03-13-2023 02:47 AM
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:
Business rule:
(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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 03:51 AM
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
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 05:05 AM
Thanks!
I've tried with add above code but it looks there is still the same issue