-Andrew-
Kilo Sage

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:

 

  1. Create a new Business Rule
  2. In the "When to run" section, select "Before" and "Insert" options
  3. 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.

View solution in original post