Check is there any parent INC while resolving: If yes then check state of parent INC

Pawan Kumar Rai
Tera Contributor

Can anyone please suggest how to do below task:

 

When user set value of state field to resolved then do this: -

Check whether current incident has value in parent field

- If yes, then check whether state of parent incident is resolved / closed. (If yes then allow user to save the record)

- If above condition is false then display error message that "Parent ticket should be closed before closing child ticket"

1 ACCEPTED SOLUTION

Hi @Pawan Kumar Rai 

 

did my respone resolve your issue?? if so,

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

View solution in original post

8 REPLIES 8

Clara Lemos
Mega Sage
Mega Sage

Hi @Pawan Kumar Rai ,

 

You can create a Business Rule with condition : State Changes to Resolved

In the advanced tab you can add a script like this:

 

(function executeRule(current, previous /*null when async*/ ) {

var parentIncident = current.parent_incident;
var link = '<a href="' + current.getLink() + '">' + current.getDisplayValue() + '</a>';

if (parentIncident != '' && parentIncident.state != '6' && parentIncident.state != '7') { // verifies that there is a parent incident associated and the parent state is not Resolved/Closed
gs.addErrorMessage("Parent ticket should be closed before closing child ticket");
current.setAbortAction(true);
} else {
gs.addInfoMessage(gs.getMessage('Incident {0} has been resolved', link));
}

})(current, previous);

 

When an incident is resolved there is another business rules that runs OOTB : "Caller Close"

So I commented the lines 9 and 10 in this business rule and added the 'Incident {0} has been resolved' message in my business rule, so that you don't get duplicated Messages in your form.

 

Let me know in case I didn't get you requirement correctly and if this was helpful please mark my answer as correct 🙂

 

Cheers

Eswar Chappa
Mega Sage
Mega Sage

Hi @Pawan Kumar Rai Write a before business rule on incident table with update operation and in the script condition please use the below code:

 

function executeRule(current, previous /*, g */) {
// Check if there is a parent incident
if (current.parent) {
var parentIncident = new GlideRecord('incident');
if (parentIncident.get(current.parent)) {
var parentState = parentIncident.getValue('state');
gs.info('Parent Incident (' + parentIncident.number + ') state: ' + parentState);
}
}
})(current, previous);

 

 

Thanks & Regards,

Eswar Chappa

Mark my answer correct and Helpful if this helps you 😀

Hemanth M1
Giga Sage
Giga Sage

Hi @Pawan Kumar Rai ,

 

you don't have to write a single line of code , Condition builder are more powerful than we think , Use Business rule condition builder as below

1)when to run:

 

HemanthM1_1-1692264861665.png

2)Action:

HemanthM1_2-1692264892674.png

 

 

Output:

HemanthM1_3-1692264968039.png

 

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

Not getting "Parent incident State" in filter option....What to do?.

Thanks for above solution.