- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2019 05:25 AM
I have some Incidents (INC) that contain Incident Tasks (TASK) and would like the Incident to auto-resolve when all Incident Tasks are closed to prevent anyone from having to manually resolve the Incident ticket itself (all actionable items are contained on the tasks...this parent/child is just a grouping construct).
I created an "after" Business Rule, but it's not working and I haven't been able to figure out why. We require close code/close notes so at first I thought an absence of those in my BR script might be the reason, but even after adding those, I'm not getting the change. I've also tried the state as both '6' and 'Resolved'.
If anyone might have suggestions, I'd be very appreciative. Thanks!
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('incident_task');
gr.addQuery('incident', current.incident);
gr.addQuery('active', true);
gr.addQuery('sys_id', '!=', current.sys_id);
gr.query();
var count = gr.getRowCount();
if(count == 0)
{
var gr1 = new GlideRecord('incident');
gr1.addQuery('sys_id', current.incident);
gr1.query();
if(gr1.next())
{
gr1.state = '6';
gr1.close_code = 'Solved (Permanently)';
gr1.close_notes = "Auto-Closed based on Incident Tasks being Closed";
gr1.update();
}
}
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2019 01:34 PM
Can we try something like this.
(function executeRule(current, previous /*null when async*/) {
var count=0;
var tasks = new GlideRecord('incident_task');
tasks.addQuery('parent',current.parent);
tasks.query();
var taskcount = tasks.getRowCount();
while(tasks.next())
{
if(tasks.state == 3 ||tasks.state == 4 || tasks.state == 7)//change as required
{
count++;
}
}
if(count == taskcount)
{
var inc = new GlideRecord('incident');
inc.addQuery('sys_id',current.parent);
inc.query();
if(inc.next())
{
inc.state = 6;
inc.update();
}
}
})(current, previous);
Please mark my response as correct and helpful if it helped solved your question.
-Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2019 05:35 AM
Hi,
Are the close code and close notes applying, but just not the state?
Or nothing is?
I'm unsure if gr1.addQuery('sys_id', current.incident); this would actually pull a record...have you tried to do a gs.log statement and see what you get back?
Also, is the task already created during your tests or are you opening new and trying to do all this, etc.? Because if so...this BR only runs on Update not Insert so it wouldn't trigger it.
I'd toss a gs.log up in your first glide just to see that it's processing and doing that, then another for the second to see what record it found if any.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2019 06:12 AM
Thanks for the quick reply Allen.
The BR (called “Resolve INC when all INC Tasks Closed”) is set to run across the incident_task table, which I believe to be correct because the script is looking at the line-item tasks on the INC and supposedly closing the parent INC when none of the child items (tasks) evaluate as open.
I don't believe the BR is running at all. I'm admittedly a neophyte on debugging & logging so I posted this after never finding any activity in System Logs > All, and turning debugging on generally & watching for something on the Incident Task and Incident debugs. They appear below for giggles.
Here’s the debug on an Incident Task after closing it:
Debug OutputBusiness RulesOthers
08:46:08.374: Execute before update business rules on incident_task:TASK0038296 before engines (order <1000)
08:46:08.375: Global ==> 'Task Active State Management' on incident_task:TASK0038296
08:46:08.376: Global <== 'Task Active State Management' on incident_task:TASK0038296
08:46:08.376: Global === Skipping 'reassignment counter' on incident_task:TASK0038296; condition not satisfied: Condition: current.assignment_group.changes()
08:46:08.377: Global === Skipping 'Stamp Approvals' on incident_task:TASK0038296; condition not satisfied: Condition: current.approval.changes()
08:46:08.377: Global ==> 'mark closed' on incident_task:TASK0038296
08:46:08.378: Global active: 1 => 0
08:46:08.378: Global <== 'mark closed' on incident_task:TASK0038296
08:46:08.378: Global === Skipping 'task closer' on incident_task:TASK0038296; condition not satisfied: Condition: current.sys_class_name != "dmn_demand" && current.sys_class_name != 'idea'; Filter Condition: activeCHANGESFROMtrue^active=false^state!=3^state!=4^state!=7^state!=8^EQ
08:46:08.379: Global === Skipping 'task reopener' on incident_task:TASK0038296; condition not satisfied: Condition: new TaskStateUtil(current).runTaskReopener()
08:46:08.379: Finished executing before update business rules on incident_task:TASK0038296 before engines (order <1000)
08:46:08.383: Execute before update business rules on incident_task:TASK0038296 after engines (order >=1000)
08:46:08.384: Global === Skipping 'live feed events' on incident_task:TASK0038296; condition not satisfied: Condition: new GlideappLiveFeedEventHandler().watchedTable(current.getTableName());
08:46:08.385: Global ==> 'metrics events' on incident_task:TASK0038296
08:46:08.393: Global <== 'metrics events' on incident_task:TASK0038296
08:46:08.394: Global ==> 'Set Closure Fields' on incident_task:TASK0038296
08:46:08.394: Global closed_at: => 2019-04-22 12:46:08
08:46:08.394: Global closed_by: => eb3f32e6db07a20070995434ce961992
08:46:08.394: Global <== 'Set Closure Fields' on incident_task:TASK0038296
08:46:08.394: Finished executing before update business rules on incident_task:TASK0038296 after engines (order >=1000)
08:46:08.423: Execute after update business rules on incident_task:TASK0038296 before engines (order <1000)
08:46:08.428: Global === Skipping 'Affected cost center notifications' on incident_task:TASK0038296; condition not satisfied: Condition: javascript:new AffectedUtils().hasAffected(current, "task_cost_center", "task");
08:46:08.432: Global === Skipping 'Affected group notifications' on incident_task:TASK0038296; condition not satisfied: Condition: javascript:new AffectedUtils().hasAffected(current, "task_group", "task");
08:46:08.436: Global === Skipping 'Affected location notifications' on incident_task:TASK0038296; condition not satisfied: Condition: javascript:new AffectedUtils().hasAffected(current, "task_location", "task");
08:46:08.436: Global === Skipping 'Cancel Workflows Upon Cancellation' on incident_task:TASK0038296; condition not satisfied: Condition: (current.getTableName() != 'sysapproval_group') && (current.getTableName() != 'rm_story') && (current.getTableName() != 'rm_release') && (current.getTableName() != 'incident') && (current.getTableName() != 'problem') && (current.state.changesTo(4))
08:46:08.437: Global ==> 'Moot Approvals Upon Cancellation' on incident_task:TASK0038296
08:46:08.445: Global <== 'Moot Approvals Upon Cancellation' on incident_task:TASK0038296
08:46:08.445: Global ==> 'Resolve INC when all INC Tasks Closed' on incident_task:TASK0038296
08:46:08.448: Global <== 'Resolve INC when all INC Tasks Closed' on incident_task:TASK0038296
08:46:08.448: Global === Skipping 'Sync BS with Impacted Services' on incident_task:TASK0038296; condition not satisfied: Condition: current.business_service.changes(); Filter Condition: sys_class_name=incident^ORsys_class_name=problem^ORsys_class_name=change_request^EQ
08:46:08.449: Global === Skipping 'Sync CI with Affected CIs' on incident_task:TASK0038296; condition not satisfied: Condition: current.cmdb_ci.changes()
08:46:08.449: Global ==> 'task events' on incident_task:TASK0038296
08:46:08.450: Global <== 'task events' on incident_task:TASK0038296
08:46:08.451: Global === Skipping 'Task Time Worked' on incident_task:TASK0038296; condition not satisfied: Condition: current.time_worked.changes()
08:46:08.451: Global === Skipping 'Process SLAs' on incident_task:TASK0038296; condition not satisfied: Condition: (gs.getProperty('com.snc.sla.engine.version','2010') == '2010')
08:46:08.451: Global ==> 'Run SLAs' on incident_task:TASK0038296
08:46:08.469: Global <== 'Run SLAs' on incident_task:TASK0038296
08:46:08.474: Global === Skipping 'Affected ci notifications' on incident_task:TASK0038296; condition not satisfied: Condition: javascript:new AffectedUtils().hasAffected(current, "task_ci", "task");
08:46:08.474: Global ==> 'task survey events' on incident_task:TASK0038296
08:46:08.478: Global <== 'task survey events' on incident_task:TASK0038296
08:46:08.479: Global ==> 'SNC - Run parent workflows' on incident_task:TASK0038296
08:46:08.485: Global <== 'SNC - Run parent workflows' on incident_task:TASK0038296
08:46:08.486: Execute before insert business rules on sys_trigger:ASYNC: Process Task Rate Cards before engines (order <1000)
08:46:08.487: Global ==> 'Ensure Valid Schedule' on sys_trigger:ASYNC: Process Task Rate Cards
08:46:08.488: Global <== 'Ensure Valid Schedule' on sys_trigger:ASYNC: Process Task Rate Cards
08:46:08.488: Finished executing before insert business rules on sys_trigger:ASYNC: Process Task Rate Cards before engines (order <1000)
08:46:08.488: Execute after insert business rules on sys_trigger:ASYNC: Process Task Rate Cards before engines (order <1000)
08:46:08.489: Global === Skipping 'Propagate run all nodes changes' on sys_trigger:ASYNC: Process Task Rate Cards; condition not satisfied: Condition: current.system_id == "ACTIVE NODES" || current.system_id == "ALL NODES" || (previous != null && (previous.system_id == "ALL NODES" || previous.system_id == "ACTIVE NODES"))
08:46:08.489: Global ==> 'Randomize minute for UA jobs' on sys_trigger:ASYNC: Process Task Rate Cards
08:46:08.490: Global <== 'Randomize minute for UA jobs' on sys_trigger:ASYNC: Process Task Rate Cards
08:46:08.490: Finished executing after insert business rules on sys_trigger:ASYNC: Process Task Rate Cards before engines (order <1000)
08:46:08.490: Finished executing after update business rules on incident_task:TASK0038296 before engines (order <1000)
08:46:08.574: >>> Preceding lines from previous transaction
08:46:08.594: Execute before_display before business rules on incident_task:TASK0038296
08:46:08.594: Global ==> 'Build scratchpad for task' on incident_task:TASK0038296
08:46:08.595: Global <== 'Build scratchpad for task' on incident_task:TASK0038296
08:46:08.595: Global === Skipping 'Calc SLAs on Display' on incident_task:TASK0038296; condition not satisfied: Condition: gs.getProperty("glide.sla.calculate_on_display") == "true" && gs.getProperty("com.snc.sla.run_old_sla_engine") != "true" && !current.isNewRecord()
08:46:08.595: Finished executing before_display before business rules on incident_task:TASK0038296
08:46:08.599: Execute before query business rules on live_group_member:Created
08:46:08.599: Global ==> 'LiveFeed Group Member Visibility' on live_group_member:Created
08:46:08.600: Global <== 'LiveFeed Group Member Visibility' on live_group_member:Created
08:46:08.600: Global ==> 'LiveFeed Group Member Visibility 2.0' on live_group_member:Created
08:46:08.606: Global <== 'LiveFeed Group Member Visibility 2.0' on live_group_member:Created
08:46:08.606: Finished executing before query business rules on live_group_member:Created
08:46:08.622: Execute before query business rules on incident:
08:46:08.622: Global ==> 'incident query' on incident:
08:46:08.624: Global <== 'incident query' on incident:
08:46:08.624: Finished executing before query business rules on incident:
08:46:08.627: Execute before query business rules on sys_user:
08:46:08.628: Global === Skipping 'user query' on sys_user:; condition not satisfied: Condition: gs.getSession().isInteractive() && !gs.hasRole("admin")
08:46:08.628: Finished executing before query business rules on sys_user:
08:46:08.633: Execute before query business rules on sys_user_group:
08:46:08.633: Global ==> 'group query' on sys_user_group:
08:46:08.634: Global <== 'group query' on sys_user_group:
08:46:08.634: Global ==> 'Hide Groups in Assignment Group' on sys_user_group:
08:46:08.635: Global <== 'Hide Groups in Assignment Group' on sys_user_group:
08:46:08.635: Finished executing before query business rules on sys_user_group:
And here’s the Debug on the parent Incident, after marking two existing Incident Tasks as “Closed Complete” and then Updating the parent Incident (without observing its State change).
Debug OutputBusiness RulesOthers
AppsGlobalSplunk Integration
08:55:50.674: Execute before query business rules on incident:
08:55:50.674: Global ==> 'incident query' on incident:
08:55:50.675: Global <== 'incident query' on incident:
08:55:50.675: Finished executing before query business rules on incident:
08:55:50.747: >>> Preceding lines from previous transaction
08:55:50.786: Execute before query business rules on incident:
08:55:50.786: Global ==> 'incident query' on incident:
08:55:50.787: Global <== 'incident query' on incident:
08:55:50.787: Finished executing before query business rules on incident:
08:55:50.789: Execute before_display before business rules on incident:INC0084521
08:55:50.790: App:Splunk Integration === Skipping 'Copy Splunk URL to scratchpad' on incident:INC0084521; condition not satisfied: Filter Condition: x_splu2_splunk_ser_splunk_urlISNOTEMPTY^EQ
08:55:50.790: Global ==> 'Build scratchpad for task' on incident:INC0084521
08:55:50.791: Global <== 'Build scratchpad for task' on incident:INC0084521
08:55:50.791: Global === Skipping 'Calc SLAs on Display' on incident:INC0084521; condition not satisfied: Condition: gs.getProperty("glide.sla.calculate_on_display") == "true" && gs.getProperty("com.snc.sla.run_old_sla_engine") != "true" && !current.isNewRecord()
08:55:50.791: Global ==> 'Load incident models into scratchpad' on incident:INC0084521
08:55:50.795: Global <== 'Load incident models into scratchpad' on incident:INC0084521
08:55:50.795: Global === Skipping 'TEGNA - Prompt for Category Selection' on incident:INC0084521; condition not satisfied: Filter Condition: category=Other^ORcategory=inquiry^subcategory=Other^ORsubcategory=Other Inquiry^ORsubcategory=Other Inquiry/Help^EQ; Role Condition: itil
08:55:50.795: Finished executing before_display before business rules on incident:INC0084521
08:55:50.799: Execute before query business rules on live_group_member:Created
08:55:50.799: Global ==> 'LiveFeed Group Member Visibility' on live_group_member:Created
08:55:50.800: Global <== 'LiveFeed Group Member Visibility' on live_group_member:Created
08:55:50.800: Global ==> 'LiveFeed Group Member Visibility 2.0' on live_group_member:Created
08:55:50.806: Global <== 'LiveFeed Group Member Visibility 2.0' on live_group_member:Created
08:55:50.806: Finished executing before query business rules on live_group_member:Created
08:55:50.828: Execute before query business rules on sys_user:
08:55:50.829: Global === Skipping 'user query' on sys_user:; condition not satisfied: Condition: gs.getSession().isInteractive() && !gs.hasRole("admin")
08:55:50.829: Finished executing before query business rules on sys_user:
08:55:50.842: Execute before query business rules on sys_user_group:
08:55:50.842: Global ==> 'group query' on sys_user_group:
08:55:50.843: Global <== 'group query' on sys_user_group:
08:55:50.843: Global ==> 'Hide Groups in Assignment Group' on sys_user_group:
08:55:50.844: Global <== 'Hide Groups in Assignment Group' on sys_user_group:
08:55:50.844: Finished executing before query business rules on sys_user_group:
08:55:50.859: Execute before query business rules on sys_user:
08:55:50.859: Global === Skipping 'user query' on sys_user:; condition not satisfied: Condition: gs.getSession().isInteractive() && !gs.hasRole("admin")
08:55:50.859: Finished executing before query business rules on sys_user:
08:55:50.891: Execute before query business rules on incident:
08:55:50.892: Global ==> 'incident query' on incident:
08:55:50.892: Global <== 'incident query' on incident:
08:55:50.892: Finished executing before query business rules on incident:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2019 06:17 AM
Add a 'message' to the BR to see if it's running or not. Force it to run and the message should pop-up. That's usually what I do (make sure you remove it after confirming it runs appropriately).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2019 06:24 AM
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('incident_task'); <--Have you tried a GlideAggregate instead?
gr.addQuery('incident', current.incident);
gr.addQuery('active', true);
gr.addQuery('sys_id', '!=', current.sys_id);
gr.query();
var count = gr.getRowCount(); <--Add an alert here to verify your Row Count is accurate
if(count == 0)
{
var gr1 = new GlideRecord('incident');
gr1.addQuery('sys_id', current.incident);
gr1.query();
if(gr1.next())
{
gr1.state = '6';
gr1.close_code = 'Solved (Permanently)'; <--Check this, you want the actual value of the choice
gr1.close_notes = "Auto-Closed based on Incident Tasks being Closed";
gr1.update();
}
}
})(current, previous);