File tree Expand file tree Collapse file tree
Server-Side Components/Business Rules/Automatically Throttle Incidents Raised by Same User Within Short Timeframe Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ( function executeRule ( current , gsn , gs ) {
2+
3+ var limit = 3 ;
4+ var windowMins = 10 ;
5+
6+ var recentIncidents = new GlideRecord ( 'incident' ) ;
7+ recentIncidents . addQuery ( 'caller_id' , current . caller_id ) ;
8+
9+ var now = new GlideDateTime ( ) ;
10+ var cutoff = new GlideDateTime ( ) ;
11+ cutoff . addMinutes ( - windowMins ) ;
12+
13+ recentIncidents . addQuery ( 'sys_created_on' , '>=' , cutoff ) ;
14+ recentIncidents . query ( ) ;
15+
16+ var count = 0 ;
17+ while ( recentIncidents . next ( ) ) {
18+ count ++ ;
19+ }
20+
21+ if ( count >= limit ) {
22+ gs . addErrorMessage ( "You have submitted too many incidents in a short time. Please wait before submitting more." ) ;
23+ current . setAbortAction ( true ) ;
24+ }
25+
26+ } ) ( current , gsn , gs ) ;
You can’t perform that action at this time.
0 commit comments