Skip to content

Commit 9442221

Browse files
Create BeforeBRScript.js
1 parent 06c5594 commit 9442221

File tree

1 file changed

+21
-0
lines changed
  • Server-Side Components/Business Rules/Prevent Duplicate Incident Creation within 24 Hours

1 file changed

+21
-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);

0 commit comments

Comments
 (0)