Skip to content

Commit f6f83df

Browse files
Prevent duplicate incident creation within 24 hours (#2637)
* Create BeforeBRScript.js * Create README.md
1 parent 2b2f9d6 commit f6f83df

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
(function executeRule(current, previous /*null when async*/) {
2+
3+
// Only run for active incidents
4+
if (!current.caller_id || !current.short_description)
5+
return;
6+
7+
// Create a GlideRecord on the incident table
8+
var gr = new GlideRecord('incident');
9+
gr.addQuery('caller_id', current.caller_id); // Same caller
10+
gr.addQuery('short_description', current.short_description); // Same issue text
11+
gr.addQuery('sys_created_on', '>=', gs.hoursAgoStart(24)); // Within last 24 hours
12+
gr.addQuery('state', '!=', 7); // Exclude closed incidents
13+
gr.query();
14+
15+
if (gr.next()) {
16+
// Stop insert and show an error
17+
gs.addErrorMessage("A similar incident has already been raised within the last 24 hours: " + gr.number);
18+
current.setAbortAction(true); // Prevent record creation
19+
}
20+
21+
})(current, previous);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Prevent Duplicate Incident Creation within 24 Hours
2+
3+
1. Write a Business Rule - Before Insert
4+
2. Select the Incident Table
5+
3. Only run/execute for all the active incidents
6+
4. By Gliding the Incident Table will get the caller_id, short_description for checking the current caller and text provided for the short description
7+
5. Querying the Incident Table as created within 24 Hours and excluding the closed incidents
8+
6. Stop insert and show an error message
9+
7. Prevent Incident record creation

0 commit comments

Comments
 (0)