- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2020 04:49 AM
Hi,
We have a custom status called "Awaiting User Acceptance"(AUA). If we change the state from any other state to AUA in incident form, and save the changes, then this incident should be automatically resolved after 24hrs. For that, we created a scheduled job(scheduled script execution) to automatically resolve the AUA incidents.
Here is the code:
// This script automatically closes incidents that are resolved
// and haven't been updated in the specified number of days.
// To place a comment in the incident, uncomment the "gr.comments" line.
autoCloseIncidents();
function autoCloseIncidents() {
var pn = 1; // This variable specifies the numbers of days before an incident is auto-closed
var gr = new GlideRecord('incident');
gr.addQuery('incident_state', 15); //AwaitingUserAcceeptance=15
gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(pn));
// gr.addQuery('assignment_group','d625dccec0a8016700a222a0f7900d06');
gr.query();
while(gr.next()) {
gr.incident_state = IncidentState.RESOLVED;
// gr.comments = 'Incident automatically closed after ' + pn + ' days in the User Awaiting Acceptance state.';
//gr.active = false;
gr.update();
}
Issue:
It is not resolving the child incidents associated to the parent incident. If I change the state to "IncidentState.CLOSED", then it is automatically closing the child incidents as well.
What should I do to auto-resolve the child incidents as well?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2020 05:44 AM
If you change an incident to Resolved while viewing the incident, do child incidents get updated to Resolved? There is a condition on the OOB business rule
current.state.changesTo(IncidentState.RESOLVED)
and your scheduled job is setting incident_state. I know there's a BR that keeps state and incident state in sync, but maybe there's a timing issue, so if manually changing an incident State to Resolved works, then try changing the scheduled job script to
gr.state = 6;
or maybe gr.state = IncidentState.RESOLVED;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2020 04:57 AM
Resolving child incidents when the parent incident state changes to Resolved is out of the box functionality, due to a business rule on the incident table named Update Child Incidents. Is this active in your instance? The beginning of the script is this - maybe yours was changed to IncidentState.CLOSED?
function updateChildIncidents() {
if (current.state.changesTo(IncidentState.RESOLVED))
resolveChildIncidents();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2020 05:12 AM
This "Update Child Incidents" OOB business rule is active in my instance, and it is same as the code you placed(i.e NOT changed to IncidentState.CLOSED).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2020 05:44 AM
If you change an incident to Resolved while viewing the incident, do child incidents get updated to Resolved? There is a condition on the OOB business rule
current.state.changesTo(IncidentState.RESOLVED)
and your scheduled job is setting incident_state. I know there's a BR that keeps state and incident state in sync, but maybe there's a timing issue, so if manually changing an incident State to Resolved works, then try changing the scheduled job script to
gr.state = 6;
or maybe gr.state = IncidentState.RESOLVED;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2020 05:56 AM
Thank you! It worked!!