diff --git a/Server-Side Components/Business Rules/Automatically Throttle Incidents Raised by Same User Within Short Timeframe/README.md b/Server-Side Components/Business Rules/Automatically Throttle Incidents Raised by Same User Within Short Timeframe/README.md new file mode 100644 index 0000000000..5f4567784c --- /dev/null +++ b/Server-Side Components/Business Rules/Automatically Throttle Incidents Raised by Same User Within Short Timeframe/README.md @@ -0,0 +1,8 @@ +This business rule prevents users from submitting too many incidents in a short time, acting as a rate-limiting mechanism to reduce spam or misuse of the incident form. + +What It Does: +-Checks how many incidents the same caller has submitted in the last 10 minutes. +-If the number of incidents is 3 or more, the rule: +-Blocks the current incident from being submitted. +-Displays an error message: +"You have submitted too many incidents in a short time. Please wait before submitting more." diff --git a/Server-Side Components/Business Rules/Automatically Throttle Incidents Raised by Same User Within Short Timeframe/code.js b/Server-Side Components/Business Rules/Automatically Throttle Incidents Raised by Same User Within Short Timeframe/code.js new file mode 100644 index 0000000000..41913d1981 --- /dev/null +++ b/Server-Side Components/Business Rules/Automatically Throttle Incidents Raised by Same User Within Short Timeframe/code.js @@ -0,0 +1,26 @@ +(function executeRule(current, gsn, gs) { + + var limit = 3; + var windowMins = 10; + + var recentIncidents = new GlideRecord('incident'); + recentIncidents.addQuery('caller_id', current.caller_id); + + var now = new GlideDateTime(); + var cutoff = new GlideDateTime(); + cutoff.addMinutes(-windowMins); + + recentIncidents.addQuery('sys_created_on', '>=', cutoff); + recentIncidents.query(); + + var count = 0; + while (recentIncidents.next()) { + count++; + } + + if (count >= limit) { + gs.addErrorMessage("You have submitted too many incidents in a short time. Please wait before submitting more."); + current.setAbortAction(true); + } + +})(current, gsn, gs);