File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Server-Side Components/Business Rules/Prevent Duplicate Incident Creation within 24 Hours Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 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 ) ;
You can’t perform that action at this time.
0 commit comments