- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2016 06:31 AM
Some of my incidents have child tasks associated to them. I had it set up, so that when all the child tasks were closed, the parent incident closed too using a business rule. All working fine.
I have had to change this, so that parent incident can close when:
1.) all their child tasks are closed and
2.) the incident follow_up date has passed
My thought is to use a scheduled job (scheduled script execution) that runs nightly and for any incidents that meet these requirements are closed. I am having trouble setting this up. Can anyone please advise if this is the best method and also any resources to assist?
Many thanks,
Dan
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2016 07:02 AM
I might do something a little more like this. I have a habit of using encoded queries when I work with dates, mainly so I can test it first in the condition builder and don't have to worry about what is supported where.
var inc = new GlideRecord('incident');
inc.addEncodedQuery('follow_up<javascript:gs.minutesAgoStart(0)');
inc.addActiveQuery();
inc.query();
while (inc.next()) {
var rec = new GlideRecord('u_tasks');
rec.addQuery('parent', inc.getValue('sys_id'));
rec.addQuery('state', 'IN', '3,4');
rec.query();
if (!rec.hasNext()) {
gs.log("incident resolved " + inc.number);
//close incident
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2016 06:43 AM
Hi Dan,
Since you're checking a date I would go ahead and do this through a scheduled job. I would query the incident table for incidents where the date is in the past, then iterate through each incident and query the incident task table for any open tasks related to that incident.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2016 06:48 AM
Thanks Brad,
Can you confirm I am on the right lines doing something similar below?
var inc = new GlideRecord('incident');
inc.addQuery('follow_up', '<', gs.minutesAgoStart(0));
inc.query();
while(inc.next()) {
var rec = new GlideRecord('u_tasks');
rec.addQuery('parent', inc);
rec.addQuery('state', 'IN', '3, 4');
rec.query();
if(rec.next()){
//If we find any active change tasks do nothing
}
else{
gs.log("incident resolved " + inc.number);
//close incident
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2016 07:02 AM
I might do something a little more like this. I have a habit of using encoded queries when I work with dates, mainly so I can test it first in the condition builder and don't have to worry about what is supported where.
var inc = new GlideRecord('incident');
inc.addEncodedQuery('follow_up<javascript:gs.minutesAgoStart(0)');
inc.addActiveQuery();
inc.query();
while (inc.next()) {
var rec = new GlideRecord('u_tasks');
rec.addQuery('parent', inc.getValue('sys_id'));
rec.addQuery('state', 'IN', '3,4');
rec.query();
if (!rec.hasNext()) {
gs.log("incident resolved " + inc.number);
//close incident
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2016 07:48 AM
Thank you, that has worked great.