Incident Form to Restrict only to allow 1 child to parent Incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2024 12:25 AM
Hi,
Need help below is my Requirement on Incident form
Need to create Business rule When any user tries to add parent incident number on any incident form it should check the parent already has any other child incident
if No update the parent incident number to the incident form
if Yes needs to pop up message "the selected parent incident already has child"
like wise if user tries to add child incident to the incident form it should check the child has already parent or not
If yes it should give error message the selected child incident already has parent
If No it should allow
In simple each parent will have one child
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2024 12:50 AM
Hi @harinya I'd suggest before insert/update business rule for this requirement.
Follow this script sample for business rule:
(function executeRule(current, previous) {
if (current.parent.nil()) {
// No parent added on incident, so no need to check further
return;
}
var childGR = new GlideRecord('incident');
childGR.addQuery(parent, current.parent);
childGR.query();
if (!childGR.hasNext()) {
// No other child found
gs.addInfoMessage('Parent added to incident.');
} else {
// Other children exist
gs.abortAction('Parent incident already has other child.');
}
})(current, previous);
Hope this helps!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2024 12:55 AM
Hi @harinya ,
I tried your problem in my PDI and it works for me. Please refer below steps
Create Before BR and add table Incident(you can add any table), add Filter condition like Parent Incident changes and add below code
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord('incident');
gr.addQuery('active', true);
gr.addQuery('parent_incident', current.parent_incident);
gr.query();
if (gr.next()) {
current.setAbortAction(true);
gs.addErrorMessage('This Incident has Child');
}
})(current, previous);
Result :
Incident INC0010408 already a parent of another incident and I'm trying to add same parent incident is INC0010408 so it did not allow to update
Now I'll save that record
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2024 03:19 AM
Thanks so much for quick Response, it helps me

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2024 03:26 AM - edited ‎04-16-2024 03:34 AM
Hi @harinya ,
That's great.😊
Please mark my answer correct and helpful if this helps you
Thanks and Regards
Sarthak