Skip to content

Commit 06260b4

Browse files
authored
Automatically Throttle Incidents Raised by Same User Within Short Timeframe (ServiceNowDevProgram#1956)
* Create code.js * Create README.md
1 parent 1eae7e3 commit 06260b4

File tree

2 files changed

+34
-0
lines changed
  • Server-Side Components/Business Rules/Automatically Throttle Incidents Raised by Same User Within Short Timeframe

2 files changed

+34
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
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.
2+
3+
What It Does:
4+
-Checks how many incidents the same caller has submitted in the last 10 minutes.
5+
-If the number of incidents is 3 or more, the rule:
6+
-Blocks the current incident from being submitted.
7+
-Displays an error message:
8+
"You have submitted too many incidents in a short time. Please wait before submitting more."
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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);

0 commit comments

Comments
 (0)