SetAbortAction is not working in BR

nowitsvashu
Tera Guru

I'm using this br but setabortaction is not working as it shows invalid update but shows the error message

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

	// Add your code here
	var gr = new GlideRecord('incident');
	gr.addQuery('state','!=','7').addCondition('parent_incident',current.sys_id);
	gr.query();
	if(gr.hasNext()){
		gs.addErrorMessage("Please close child incidents.");
		current.setAbortAction(true);
	}

})(current, previous);
5 REPLIES 5

Harish KM
Kilo Patron
Kilo Patron

Hi @nowitsvashu please use like below and avoid using gr

var inc = new GlideRecord('incident');
inc.addQuery('parent_incident',current.sys_id);
inc.addQuery('state','!=','7');
inc.query();
if(inc.hasNext()){
gs.addErrorMessage("Please close child incidents.");
current.setAbortAction(true);
}

Regards
Harish

Thankyou for your reply @Harish KM .
I used your script but its again showing the same error "invalid update" and setabortaction still not working.

 

nowitsvashu_0-1709710897084.png

 

Hi @nowitsvashu that's fine you get this message invalid update because of the setAbortAction, this mean the record did not update successfully which works as required

Regards
Harish

Hi @nowitsvashu there could be more than 1 child incidents, so use while loop instead of if condition

var inc = new GlideRecord('incident');
inc.addQuery('parent_incident',current.sys_id);
inc.addQuery('state','!=','7');
inc.query();
while(inc.hasNext()){
gs.addErrorMessage("Please close child incidents.");
current.setAbortAction(true);
}

Regards
Harish