- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-15-2018 06:18 AM
I created a table(Razor) which acts as child to the incident table. When the State in every child record is changed to Closed State,then the parent Incident Table should automatically..close the Incident Ticket..
Note:"i doesn't want to populate the result to the incident,it should automatically close when the child incidents are closed"
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-15-2018 06:28 AM
You'll want to run an 'After Update' business rule on the 'u_razor' table that looks like this...
Condition: current.active.changesTo(false) && current.parent.sys_class_name == 'incident'
Script:
// Query for associated records related to the same parent
var inc = new GlideRecord('u_razor');
inc.addQuery('parent', current.parent); // Records related to same parent
inc.addQuery('sys_id' '!=', current.sys_id); // Exclude this record
inc.addActiveQuery();
inc.query();
if (!inc.next()) {
// If there are no other active records associated to the same parent
// Close the parent
var parInc = new GlideRecord('incident');
parInc.get(current.getValue('parent'));
parInc.state = 7; // Close the incident
parInc.active = false;
parInc.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-15-2018 06:28 AM
You'll want to run an 'After Update' business rule on the 'u_razor' table that looks like this...
Condition: current.active.changesTo(false) && current.parent.sys_class_name == 'incident'
Script:
// Query for associated records related to the same parent
var inc = new GlideRecord('u_razor');
inc.addQuery('parent', current.parent); // Records related to same parent
inc.addQuery('sys_id' '!=', current.sys_id); // Exclude this record
inc.addActiveQuery();
inc.query();
if (!inc.next()) {
// If there are no other active records associated to the same parent
// Close the parent
var parInc = new GlideRecord('incident');
parInc.get(current.getValue('parent'));
parInc.state = 7; // Close the incident
parInc.active = false;
parInc.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2018 02:44 AM
Thank you mark for your reply...
u haven't mentioned about the child table's State..how come incident know the State of the child table..to close the incident

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2018 05:00 AM
We know about the child table state because that is where the business rule is triggered from.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2018 02:51 AM
I tried to count the child records (i.e) present in child (blade) it closes the incident when one child record is closed..it need to check for every child record whether it is closed or not and then close the incident ticket
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('incident');
if (gr.get(current.u_business_service)) {
if (checkchild(current.sys_id)) {
gs.addInfoMessage('All child incidents are now resolved');
gr.state=7;
gr.close_code = 'Solved (Work Around)';
gr.close_notes = 'The incident is Resolved as the Related Problem is Closed/Resolved';
gr.update();
}
else {
gs.addInfoMessage('Not all child incidents are resolved');
}
}
else {
gs.addInfoMessage('Current incident does not have a parent incident');
}
function checkchild(parentID) {
var rec = new GlideRecord("u_blade");
rec.addQuery("parent_incident", parentID);
rec.addActiveQuery();
rec.query();
var c=rec.getRowCount();
if (c.hasNext()) {
gs.addInfoMessage('child incident are closed');
return true;
}
else {
gs.addInfoMessage('child incidents not closed');
return false;
}
}
})(current, previous);