- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2023 04:35 AM
Hi All,
We have a requirement to limit the creation of incident in a day for a user.
A user can only create five incident a day for a particular category and on 6th attempt an error should pop up.
How can I achieve this one.
Any help would be appreciated. Thanks in Advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2023 04:52 AM
Hi Anamika,
You can create a Business Rule that runs on the creation of the incident and checks the number of incidents created by the user for the specified category:
- Create a new Business Rule
- In the "When to run" section, select "Before" and "Insert" options
- In the "Advanced" section, add the following code:
(function executeRule(current, previous /*null when async*/) {
var category = current.category; // replace with your incident category field name
var user = current.opened_by; // replace with your incident user field name
var limit = 5; // set the limit to 5 incidents per day
var incidentCount = new GlideAggregate('incident');
incidentCount.addQuery('category', category);
incidentCount.addQuery('opened_by', user);
incidentCount.addAggregate('COUNT');
incidentCount.query();
incidentCount.next();
var count = incidentCount.getAggregate('COUNT');
if (count >= limit) {
gs.addErrorMessage("You have already created " + count + " incidents for this category today. You cannot create more than " + limit + " incidents per day.");
current.setAbortAction(true);
}
})(current, previous);
- Replace "category" and "user" with the actual field names for the incident category and user, respectively
- Set the "limit" variable to the desired limit for the number of incidents per day
Hopefully this helps you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2023 05:01 AM
Hi,
Although I'm having trouble understanding why you would want to limit users from reporting more than 5 incidents a day, I can still help you on the way (but feel free to elaborate on the requirement).
You could set up a business rule for this.
Something like below should work:
Business rule that runs before insert, no conditions.
Also, I would like to point out, that this solution will also prohibit a fulfiller user from creating max 5 incidents per day, which seems unwise 😀
You might want to tweak it, so that it only runs for non ITIL users.
(function executeRule(current, previous /*null when async*/) {
var userID = current.getValue('opened_by');
var incGR = new GlideRecord('incident');
incGR.addQuery('opened_by', userID);
incGR.addQuery('category', current.getValue('category'));
incGR.addEncodedQuery('sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
incGR.query();
if (incGR.getRowCount() > 4){
gs.addErrorMessage('Cannot create more than 5 incidents on same category on the same day');
current.setAbortAction(true);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2023 04:52 AM
Hi Anamika,
You can create a Business Rule that runs on the creation of the incident and checks the number of incidents created by the user for the specified category:
- Create a new Business Rule
- In the "When to run" section, select "Before" and "Insert" options
- In the "Advanced" section, add the following code:
(function executeRule(current, previous /*null when async*/) {
var category = current.category; // replace with your incident category field name
var user = current.opened_by; // replace with your incident user field name
var limit = 5; // set the limit to 5 incidents per day
var incidentCount = new GlideAggregate('incident');
incidentCount.addQuery('category', category);
incidentCount.addQuery('opened_by', user);
incidentCount.addAggregate('COUNT');
incidentCount.query();
incidentCount.next();
var count = incidentCount.getAggregate('COUNT');
if (count >= limit) {
gs.addErrorMessage("You have already created " + count + " incidents for this category today. You cannot create more than " + limit + " incidents per day.");
current.setAbortAction(true);
}
})(current, previous);
- Replace "category" and "user" with the actual field names for the incident category and user, respectively
- Set the "limit" variable to the desired limit for the number of incidents per day
Hopefully this helps you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2024 10:49 AM
Hi @-Andrew-
i have a similar type of requirement, want to stop to incident creation through mail, and condition is we need to check last four hours, and more than 20 records , if that condition met need to stop creating incident.
could you please help me how to achieve this through inbound email action

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2023 05:01 AM
Hi,
Although I'm having trouble understanding why you would want to limit users from reporting more than 5 incidents a day, I can still help you on the way (but feel free to elaborate on the requirement).
You could set up a business rule for this.
Something like below should work:
Business rule that runs before insert, no conditions.
Also, I would like to point out, that this solution will also prohibit a fulfiller user from creating max 5 incidents per day, which seems unwise 😀
You might want to tweak it, so that it only runs for non ITIL users.
(function executeRule(current, previous /*null when async*/) {
var userID = current.getValue('opened_by');
var incGR = new GlideRecord('incident');
incGR.addQuery('opened_by', userID);
incGR.addQuery('category', current.getValue('category'));
incGR.addEncodedQuery('sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
incGR.query();
if (incGR.getRowCount() > 4){
gs.addErrorMessage('Cannot create more than 5 incidents on same category on the same day');
current.setAbortAction(true);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2023 05:12 AM
To achieve this requirement, you would need to implement some logic on the server side that tracks the number of incidents created by each user for a particular category. Here's a simple algorithm you could use:
When a user creates an incident for a particular category, retrieve the number of incidents they have created for that category on the current day.
If the number of incidents is less than 5, allow the user to create the incident and increment the incident count for the category.
If the number of incidents is equal to 5, prevent the user from creating the incident and display an error message.
At the end of the day, reset the incident count for each category for each user.
Here's some sample code in Python that implements this algorithm using a dictionary to keep track of the incident count for each user and category:
Note that this implementation uses the current date to determine when to reset the incident count. If you need to support multiple time zones or have other requirements around the reset time, you may need to modify the implementation accordingly.