How to limit 10 records per Incident
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 05:32 AM
Hi all,
I have requirement where,
I have to check if parent record(INC0000111 ) has 10 child records , if the 10 child records are created then I should get a error message and should not be able to create more than 10 record's for a parent record.
1 REPLY 1

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 06:01 AM
@Sanket Pawar Here is the before Insert business rule you need to create on the incident table.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var glideIncidentParent = new GlideAggregate('incident');
glideIncidentParent.addQuery('parent_incident',current.parent_incident);
glideIncidentParent.addAggregate('COUNT');
glideIncidentParent.query();
if(glideIncidentParent.next()){
var incidentCount = glideIncidentParent.getAggregate('COUNT');
if(parseInt(incidentCount)>=10){
gs.addErrorMessage('Maximum child count for incident reached.');
current.setAbortAction(true); //Abort incident creation
}
}
})(current, previous);
Please mark this answer helpful and correct if it manages to address your question.