- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 03:28 AM
Business rule for when any open/unresolved task is available then you cannot change you incident state to resolved, it should throw error message.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2023 10:48 PM
My Solution:
When to Run : Before Update
Condition : State Changes to Resolved
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var taskstate = new GlideRecord('sc_task');
taskstate.addQuery('parent', current.sys_id);
taskstate.addEncodedQuery('state!=3');
taskstate.query();
if (taskstate.next()) {
gs.addErrorMessage("cannot resolve the incident because the task/s is not resolved");
current.setAbortAction(true);
gs.setRedirect(current);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2023 01:23 AM
Hi @The_Flash ,
You can create a Before Update business rule and use the below scipt
if (current.state == '6' || current.state == '7' || current.state == '8') {
var getIncidentTaskRecord = new GlideRecord('incident_task');
getIncidentTaskRecord.addQuery('incident', current.sys_id);
getIncidentTaskRecord.addQuery('state', '!=', '3,4,7'); //States of incident task
getIncidentTaskRecord.query();
if (getIncidentTaskRecord.getRowCount() >= 1) {
current.setAbortAction(true);
gs.addErrorMessage('Please close all the incident tasks before attempting to close this incident');
}
}
Please note that the above incident and task states are as based on OOB incident configuration, you might need to change the state conditions accordingly.
Please mark Helpful / Accept Solution so that it helps others with similar questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2023 04:09 AM - edited 02-19-2023 09:13 PM
Hi @The_Flash,
Business rule
BR: Before Update
Condition: State Changes to Resolved
(function executeRule(current, previous /*null when async*/) {
var incTask = new GlideRecord("incident_task");
incTask.addQuery("incident",current.sys_id);
incTask.addQuery("state!=3");
incTask.query();
if(incTask.next()){
gs.addErrorMessage(current.state+"Incident Task still not Resloved yet, please complete Incident Task first.");
current.setAbortAction(true);
}
})(current, previous);
Please hit like and mark my response as correct if that helps
Regards,
Sonali

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2023 07:24 AM - edited 02-19-2023 11:12 AM
Hello @The_Flash ,
Business rule
BR: Before Update
Condition: State is one of Resolved, Closed, Canceled.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2023 10:48 PM
My Solution:
When to Run : Before Update
Condition : State Changes to Resolved
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var taskstate = new GlideRecord('sc_task');
taskstate.addQuery('parent', current.sys_id);
taskstate.addEncodedQuery('state!=3');
taskstate.query();
if (taskstate.next()) {
gs.addErrorMessage("cannot resolve the incident because the task/s is not resolved");
current.setAbortAction(true);
gs.setRedirect(current);
}
})(current, previous);