Options
- 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.