File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
Server-Side Components/Business Rules/Prevent duplicate incidents submission Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 1+ ( function executeRule ( current , previous /*null when async*/ ) {
2+ var dup = new GlideRecord ( 'incident' ) ;
3+ dup . addQuery ( 'caller_id' , current . caller_id ) ;
4+ dup . addQuery ( 'short_description' , current . short_description ) ;
5+ dup . addQuery ( 'state' , '!=' , 6 ) ; // Exclude closed
6+ var sevenDaysAgo = new GlideDateTime ( ) ;
7+ sevenDaysAgo . addDaysUTC ( - 7 ) ;
8+ dup . addQuery ( 'sys_created_on' , '>=' , sevenDaysAgo ) ;
9+ dup . query ( ) ;
10+
11+ if ( dup . next ( ) ) {
12+ // Build URL dynamically based on instance name
13+ var instanceName = gs . getProperty ( 'instance_name' ) ;
14+ var url = gs . getProperty ( 'glide.servlet.uri' ) + 'incident.do?sys_id=' + dup . sys_id ;
15+
16+ // Add info message with hyperlink
17+ gs . addInfoMessage ( "A similar incident <a target='_blank' href='" + url + "'>" + dup . number + "</a> already exists (created within the last 7 days)." ) ;
18+
19+ // Stop creation of duplicate
20+ current . setAbortAction ( true ) ;
21+ }
22+ } ) ( current , previous ) ;
You can’t perform that action at this time.
0 commit comments