- 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 09:30 AM
Hi Brad,
Sorry all working ok for the comments using the gs.log. It will go through and list all the incidents in that state.
incident resolved INC0233344 |
incident resolved INC0233348
etc etc
But when I try to close all the incidents (and there may be multiple) with this status. It all processes the first and then stops. I may well be doing it wrong. I am using the following under the gs.log. Have you any ideas where I might be going wrong?
inc.incident_state = 6;
inc.follow_up = '';
inc.update();
Thanks a lot,
Dan