- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 06:58 AM
Hi all ,
I have created one notification to trigger notification when particular field values changed. But the notification triggers 5 times. So as per checking, The record was updating 5 times in backend when i modify the field values for testing. This is because in few of the business rules current.update() is used and the fields i am using in the notification is called in the script. So when i make those business rules inactive i get only 1 notification in system logs. But again when i make it active and start testing i again notice 5. So is there any solution to trigger only 1 notification without making the business rules inactive?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 08:37 AM
@suresh kaliappa I am assuming that you are triggering the notification via an event. In this case your best bet would be to Query the sysevent table and check if an event with your event name, table and record sys_id within last one minute has already been triggered. If yes then do not trigger the event again if no then trigger the event.
Here is the script function which you can use to check if the event with a specific name, on a specific table and on a specific record was triggered in last one minute.
//Function to check if the similar event is already triggered in last one minute
function checkEventAlreadyTriggered(eventName, tableName, recordSysID) {
var eventRec = new GlideRecord('sysevent');
eventRec.addEncodedQuery('name=' + eventName + '^table=' + tableName + '^instance=' + recordSysID + '^sys_created_on>javascript:gs.beginningOfLastMinute()');
eventRec.query();
if (eventRec.hasNext()) {
return true;
} else {
false;
}
}
Following is an example how I used in my background script to prevent repetitive events from getting generated.
var inc = new GlideRecord('incident');
if (inc.get('b8e0eb154726211092c98021336d43a0')) {
if (!checkEventAlreadyTriggered('come.snow.test.event', 'incident', 'b8e0eb154726211092c98021336d43a0')) {
gs.eventQueue('come.snow.test.event', inc, inc.number, inc.getValue('short_description'));
} else {
gs.info('Similar event has already been triggered in last one minute');
}
} else {
gs.print('Record not found');
}
//Function to check if the similar event is already triggered in last one minute
function checkEventAlreadyTriggered(eventName, tableName, recordSysID) {
var eventRec = new GlideRecord('sysevent');
eventRec.addEncodedQuery('name=' + eventName + '^table=' + tableName + '^instance=' + recordSysID + '^sys_created_on>javascript:gs.beginningOfLastMinute()');
eventRec.query();
if (eventRec.hasNext()) {
return true;
} else {
false;
}
}
You can apply same logic to prevent repetitive notification from triggering via your business rule.
Hope this helps.
Please mark this answer correct and helpful if it manages to solve your issue.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 08:37 AM
@suresh kaliappa I am assuming that you are triggering the notification via an event. In this case your best bet would be to Query the sysevent table and check if an event with your event name, table and record sys_id within last one minute has already been triggered. If yes then do not trigger the event again if no then trigger the event.
Here is the script function which you can use to check if the event with a specific name, on a specific table and on a specific record was triggered in last one minute.
//Function to check if the similar event is already triggered in last one minute
function checkEventAlreadyTriggered(eventName, tableName, recordSysID) {
var eventRec = new GlideRecord('sysevent');
eventRec.addEncodedQuery('name=' + eventName + '^table=' + tableName + '^instance=' + recordSysID + '^sys_created_on>javascript:gs.beginningOfLastMinute()');
eventRec.query();
if (eventRec.hasNext()) {
return true;
} else {
false;
}
}
Following is an example how I used in my background script to prevent repetitive events from getting generated.
var inc = new GlideRecord('incident');
if (inc.get('b8e0eb154726211092c98021336d43a0')) {
if (!checkEventAlreadyTriggered('come.snow.test.event', 'incident', 'b8e0eb154726211092c98021336d43a0')) {
gs.eventQueue('come.snow.test.event', inc, inc.number, inc.getValue('short_description'));
} else {
gs.info('Similar event has already been triggered in last one minute');
}
} else {
gs.print('Record not found');
}
//Function to check if the similar event is already triggered in last one minute
function checkEventAlreadyTriggered(eventName, tableName, recordSysID) {
var eventRec = new GlideRecord('sysevent');
eventRec.addEncodedQuery('name=' + eventName + '^table=' + tableName + '^instance=' + recordSysID + '^sys_created_on>javascript:gs.beginningOfLastMinute()');
eventRec.query();
if (eventRec.hasNext()) {
return true;
} else {
false;
}
}
You can apply same logic to prevent repetitive notification from triggering via your business rule.
Hope this helps.
Please mark this answer correct and helpful if it manages to solve your issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2023 02:04 AM
Hi Sandeep ,
Thank you for your reply. you have given good idea. but in sysevent table all 5 events triggers at same time even seconds was not mismatching. So now i am facing challenging to query any 1 unique record and to trigger the notification only at once.
Big thanks if you can assist upon this again.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2023 02:18 AM
Try the following and see if it works.
var inc = new GlideRecord('incident');
if (inc.get('b8e0eb154726211092c98021336d43a0')) {
if (!checkEventAlreadyTriggered('come.snow.test.event', 'incident', 'b8e0eb154726211092c98021336d43a0')) {
gs.eventQueue('come.snow.test.event', inc, inc.number, inc.getValue('short_description'));
var timeInMS = 1000;//1 second in milleseconds
gs.sleep(timeInMs);
} else {
gs.info('Similar event has already been triggered in last one minute');
}
} else {
gs.print('Record not found');
}