Need a script to check whether all the Incident Tasks of an Incident are in resolved state, then only the the incident state can move into Resolved state, any BR any script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2017 07:53 AM
Need a script to check whether all the Incident Tasks of an Incident are in resolved state, then only the the incident state can move into Resolved state, any BR any script?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2023 08:14 PM
Can you post a new question for this?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2023 08:38 PM
The Requirement is I need a script to check is incident state is resolved then all the incident task should be marked as closed complete automatically.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2023 05:18 AM
Hello @jayaprakash1998
Please refer to my previous post in which I tagged you.
Thanks & Regards
Kartik Magadum
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2023 10:11 PM
Hello @jayaprakash1998
To ensure that all Incident Tasks are marked as "Closed Complete" when the Incident itself is marked as "Resolved," you can use a Business Rule (BR)
Here's a script example for this Business Rule
(function executeRule(current, previous /*, display_error*/) {
if (current.state == 6 /* '6' represents the resolved state in this example */) {
// Query all related Incident Tasks for the current Incident
var incidentTaskGr = new GlideRecord('incident_task');
incidentTaskGr.addQuery('incident', current.sys_id); // Replace 'incident' with the actual reference field name
incidentTaskGr.query();
// Update all related Incident Tasks to 'Closed Complete'
while (incidentTaskGr.next()) {
incidentTaskGr.setValue('state', 7); // '7' represents the 'Closed Complete' state (change this according to your instance)
incidentTaskGr.update();
}
}
})(current, previous);
Please Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.
Thanks & Regards,
Kartik Magadum
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2023 10:07 PM
Hello @scottyharris
To ensure that all Incident Tasks of an Incident are in the resolved state before allowing the Incident itself to move into the resolved state, you can use a Business Rule (BR).
Here's a script example for such a Business Rule:
(function executeRule(current, previous /*, display_error*/) {
// Query all related Incident Tasks for the current Incident
var incidentTaskGr = new GlideRecord('incident_task');
incidentTaskGr.addQuery('incident', current.sys_id); // Replace 'incident' with the actual reference field name
incidentTaskGr.query();
// Check if all related Incident Tasks are resolved
var allResolved = true;
while (incidentTaskGr.next()) {
if (incidentTaskGr.state != 3 /* '3' is the resolved state in the incident_task table */) {
allResolved = false;
break;
}
}
// If all Incident Tasks are resolved, allow the Incident to move to the resolved state
if (allResolved) {
current.setWorkflow(false); // Disable any workflow that may be triggered
current.state = 6; // Set '6' as the resolved state (change this according to your instance)
current.update();
} else {
// If not all Incident Tasks are resolved, cancel the update
gs.addErrorMessage("All Incident Tasks must be resolved before resolving the Incident.");
current.setAbortAction(true);
}
})(current, previous);
Please Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.
Thanks & Regards,
Kartik Magadum