Child Inc tickets automatically closed when the Parent INC ticket is closed

ar1
Kilo Sage

Hi,

Can anyone please help us on the below requirement.

We want to close all the child INC tickets when the Parent INC ticket state changes to closed.
We wrote one After / update -->  Business rule but some reasons the child ticket state not changing to closed.
and also we want to copy the work notes and parent inc number from parent to child ticket work notes.

 

Script:

 

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

var num = current.number;
var inc = new GlideRecord('incident');
inc.addActiveQuery();
inc.addQuery('parent',current.sys_id);
//inc.orderByDesc('sys_created_on');
inc.query();
while(inc.next())
{
if(inc.incident_state != 7)
{
inc.incident_state = 7;
 if(JSUtil.notNill(current.comments.getJournalEntry(1)))
 {
 inc.comments = num + " : " + current.comments.getJournalEntry(1);
 }
inc.update();
}
}

 

 

Advance Thanks.
})(current, previous);

  

1 ACCEPTED SOLUTION

Hello,

 

The attached notepad contains the filter condition and the complete script just copy paste it:-

 

Please mark my answer as correct.

 

Thanks.

 

View solution in original post

22 REPLIES 22

Hi Saurav,
One doubt,
i have attached the script, in that there is a function called "updateChildren" used for resolved logic.
Do you want us to use the same for closed logic as well.

Script:

function updateChildren(fields) {

if (fields.length < 1)
return;

var rec = new GlideRecord("incident");
rec.addQuery("parent_incident", current.sys_id);
rec.addQuery("state", "!=", IncidentState.RESOLVED);
rec.addActiveQuery();
rec.query();

while (rec.next()) {

for (var i = 0; i < fields.length; i++) {
rec[fields[i].name] = fields[i].value;
}

rec.update();
}
}



Advance thanks for the support. 

Hello,

 

No i think you can exclude that for closed logic as well.

Thank you so much.

Hi Saurav,
Sorry for disturbing you.
One small doubt,
In the below script (red line) some time the output coming very strange:
Notes are coping from parent to child incident ticket.
but it's coming like this  ---> some time "NaN" or "0" also we're seeing in child INC ticket resolution notes.
"NaN copied from Parent Incident:
Test cascade closure / as Resolution"

 

Advance thanks.

if (incident.isValidField("close_notes") && incident.close_notes.nil()) {
msg = gs.getMessage('{0} copied from Parent Incident', current.close_notes.getLabel());
if (current.close_notes.toString().indexOf(msg) == 0)
incident.close_notes = current.close_notes;
else
incident.close_notes = msg + ": " + \n + current.close_notes;
}

Yeah you can hardcore the lines and do not have to keep 0, so no matter what you will not receive any such message as NaN