What is the correct way to use current.setAbortAction(true)?

bradfournier
Kilo Expert

I have a business rule in which I'm attempting to use current.setActionAbort(true), but it doesn't seem to be working as I would expect. The BR runs onBefore Update to check and see if the current record has any open subtasks. If there are open subtasks, it should stop the update of the record, and display an info message at the top of the screen. In it's current form, it does stop the record from being updated, however it reloads the page with the same field changes still displayed, and it does not show the Info message at the top of the record. I'm wondering if I'm using the 'current.setAbortAction(true)' incorrectly, or if I'm not understanding how it works in general. Any help is appreciated! Code is below:

(function executeRule(current, previous /*null when async*/) {

	var tsk = new GlideRecord('task');
	tsk.addQuery('u_parent_task',current.sys_id);
	tsk.addQuery('active',true);
	tsk.query();
	if(tsk.getRowCount() > 0) {
		gs.addInfoMessage('Please close all subtasks to close the request');
		current.setAbortAction(true);
	}

})(current, previous);
13 REPLIES 13

Shashikant Yada
Tera Guru

Hi,

 

Can you try below code:

(function executeRule(current, previous /*null when async*/) {

var tsk = new GlideRecord('task');
tsk.addQuery('u_parent_task',current.sys_id);
tsk.addQuery('active',true);
tsk.query();
if(tsk.next()) {
gs.addInfoMessage('Please close all subtasks to close the request');
current.setAbortAction(true);
}

})(current, previous);

 

Thanks
Shashikant

Hit Helpful or Correct on the impact of response.

Using that code gives me the same result.

 

Thanks,

Brad

To which table you are trying to check the Subtask? I can see you are using Task table.

 

We wrote this for RITM to check the Catalog tasks are open or not.

var activeTask = new GlideRecord('sc_task');
activeTask.addQuery('active',true);
activeTask.addQuery('request_item', current.sys_id);
activeTask.query();
if (activeTask.next()) {
gs.addErrorMessage('This Requested Item has currently opened tasks, and cannot be closed. Please close any open tasks before closing this Requested Item');
current.state = previous.state;
current.setAbortAction(true);
}

Thanks

That work for me.

 

But im not sure why put 

current.state = previous.state;

Before setAbortAction works? Any documentation or spec for that?