diff --git a/Server-Side Components/Business Rules/Service Request Submission Throttling/README.md b/Server-Side Components/Business Rules/Service Request Submission Throttling/README.md new file mode 100644 index 0000000000..329c0af811 --- /dev/null +++ b/Server-Side Components/Business Rules/Service Request Submission Throttling/README.md @@ -0,0 +1,9 @@ +This business rule in ServiceNow is designed to limit the number of service catalog requests a user can submit within a certain timeframe — specifically, 5 requests per hour. + +This rule helps throttle excessive catalog request submissions, which can: +Prevent system abuse (intentional or accidental), +Avoid spamming by users (especially in large environments) + +This ServiceNow Business Rule checks if the current user has submitted 5 or more service catalog requests (sc_request) in the past hour. If they have: +It shows an error message, And aborts the current request from being submitted. +It uses GlideAggregate to efficiently count recent requests made by the same user, and compares the count against the limit. diff --git a/Server-Side Components/Business Rules/Service Request Submission Throttling/code.js b/Server-Side Components/Business Rules/Service Request Submission Throttling/code.js new file mode 100644 index 0000000000..6eecaeb54d --- /dev/null +++ b/Server-Side Components/Business Rules/Service Request Submission Throttling/code.js @@ -0,0 +1,16 @@ +(function executeRule(current, gsn, gs) { + var user = gs.getUserID(); + var windowStart = new GlideDateTime(); + windowStart.addHours(-1); + + var gr = new GlideAggregate('sc_request'); + gr.addQuery('requested_for', user); + gr.addQuery('sys_created_on', '>=', windowStart); + gr.addAggregate('COUNT'); + gr.query(); + + if (gr.next() && parseInt(gr.getAggregate('COUNT')) >= 5) { + gs.addErrorMessage("You have reached the request submission limit. Please wait and try again later."); + current.setAbortAction(true); + } +})(current, gsn, gs);