How to limit 10 records per Incident

Sanket Pawar
Tera Contributor

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

Sandeep Rajput
Tera Patron
Tera Patron

@Sanket Pawar Here is the before Insert business rule you need to create on the incident table.

 

Screenshot 2023-11-23 at 7.28.45 PM.pngScreenshot 2023-11-23 at 7.29.26 PM.png

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