Prevent Incident resolution if Open Incident Tasks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2018 03:39 AM
Hi,
I'm looking for some help with my before Business Rule to prevent an Incident being resolved if there are open Incident Tasks. I've done the following so far:
When to run: Before
Order: 100
Update: Selected
Filter Conditions: 'State' 'changes to' 'Resolved'
This is my script:
(function executeRule(current, previous /*null when async*/) {
var incgr = new GlideRecord('incident_task');
incgr.addActiveQuery();
incgr.addQuery('incident',current.sys_id);
incgr.query();
if (incgr.hasNext()) {
current.setAbortAction(true);
gs.addErrorMessage('All Incident Tasks must be closed before an Incident can be resolved');
action.setRedirectURL(current.sys_id);
}
})(current, previous);
This is finding the open incident tasks and providing the error message. The problem is, it still moves the status to 'Resolved'. Only it hasn't committed this to the DB as if you click 'Reload Form' it moves the state back to what it was previously. So technically, the BR is working but I think it's getting stuck somewhere. I've tried adding current.state = previous.state; to it but that doesn't do anything either.
Am I doing something wrong here? New to ServiceNow so any help would be great. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2024 09:44 AM
I am running into the same exact issue and I'm using the same exact code as you are. How were you able to resolve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2018 03:54 PM
Hi Alex,
I am facing the same issue. Can you please guide me how did you resolve the issue

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2024 11:19 AM
You can do something similar with a client script. You will have to pick a state to set the state to as client script do not have access to the previous value. See below this set the state back to in progress before they can even save the records and put up the alert.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
if (newValue == 6) {//only run when state schanges to resolved.
var gr = new GlideRecord("incident_task");
gr.addQuery("incident", g_form.getUniqueValue());//sys_id of incident
gr.addQuery("active", true);
gr.query();
if (gr.next()) {
g_form.addErrorMessage("All Incident Tasks must be closed before an Incident can be resolved");
g_form.setValue("state", 2);//set state back to in progress
}
}
}