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-26-2017 08:00 AM
You can do this with a business rule. Query the incident task table, using the current incident as the parent id, and if any of those are still open, you can abort the action on the form, and display a message.
Cheers,
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2017 08:04 AM
Hi Scotty,
you can have this code in business rule
query incident task with current incident and check all incident tasks are closed or not if not then abort the action.
have before update business rule
var gr = new GlideRecord('incident_task');
gr.addQuery('parent', current.sys_id);
gr.addQuery('state', '!=' , '7,6'); // 7 and 6 means closed and resolved state
gr.query();
if(gr.getRowCount() >1){
gs.addInfoMessage('Incident cannot be resolved because all incident tasks are not closed');
current.setAbortAction(true);
}
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
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-28-2020 03:25 AM
Hi Ankur
I've tried to modify this Business Rule for Change Tasks because we have the same problem in the change process (Change State is set to Review but there are still open change tasks).
I've created ä Business Rule (before Update) for the change request table with the Filter Condition "State changes to Review".
Then modified the Script in the Advanced Tab to:
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('change_task');
gr.addQuery('parent', current.sys_id);
gr.addQuery('state', '!=' , '4'); // 4 means closed state
gr.query();
if(gr.getRowCount() >1){
gs.addInfoMessage('Change cannot be set to Review State because not all Change Tasks are closed');
current.setAbortAction(true);
}
})(current, previous);
There is no Condition set.
With this Business Rule i get the message when there are open change tasks but i also get this message when all change tasks are closed. So i can't set now the Change to State Review.
Any idea how to modify the Business Rule that it works correctely? Does the number (in this case 4) means the state in the task or in the Change?)
Thanks and regards
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2023 01:01 AM
Need a script to check
If incident is marked as resolved
then
if resolved
all the incident task should be marked as closed complete
Cheers,
Jayaprakash