The CreatorCon Call for Content is officially open! Get started here.

Incident Form to Restrict only to allow 1 child to parent Incident

harinya
Tera Contributor

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

5 REPLIES 5

dpac_nick
Tera Contributor

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!

 

 

If this works for you, please mark my answer correct or helpful.

Community Alums
Not applicable

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 

SarthakKashya2_3-1713254139760.png

 

(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

SarthakKashya2_2-1713254015520.png

 

Now I'll save that record 

SarthakKashya2_1-1713253989436.png

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

 

Thanks so much for quick Response, it helps me

Community Alums
Not applicable

Hi @harinya ,

That's great.😊

Please mark my answer correct and helpful if this helps you

 

Thanks and Regards

Sarthak