Prevent Incident resolution if Open Incident Tasks

sndev1099
Giga Expert

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.

12 REPLIES 12

What's the goal here? to not allow them to click Resolve button or change state to Resolved?

The resolve button needs to be there, but when they click on it, I need it to show an error message if there are still open Incident Tasks. The state should not change but it's moving to Resolved.

Then we definitely need to modify the UI action Resolve. Was trying a couple of things, but no luck. Will take some time to work out unless someone else has an idea.

I managed to get this working Michael. Thanks for your help.

I am also facing the same issue. Can you Please help me resolving?