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

payal13
Kilo Contributor

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


var par=current.parent;

var gr=new GlideRecord('sub_task_table_name');

gr.addQuery('parent',current.parent);
gr.addQuery('task_type','!=','next review stage');
gr.addQuery('stateNOT IN148,7');
gr.query();
if(gr.next()){

current.setAbortAction(true);
gs.addErrorMessage(' Task cannot be moved to QC ready until previous tasks are in QC Ready');

}

Hi,

For aborting the action, you need not right any script unless you have complex conditions to be verified.

Please add the conditions to the 'when to run' section of the BR.

In the 'Action' tab, add a message by clicking on 'Add a message' checkbox, click on checkbox ' abort action' and save the BR.

Thanks

payal13
Kilo Contributor

I only changed addErrorMessage to addInfoMessage and script worked fine.

Thank you all for responses.

MrMuhammad
Giga Sage

Hi,

What is your triggering condtion? if you are triggering "AFTER" update/insert then please try changing it to "BEFORE" update and execute the BR. I hope this will help. 

 

Please mark this accepted/helpful, if applicable.

 

Thanks & Regards,

Sharjeel

 

 

Regards,
Muhammad