Business Rule is not aborting UI Action

MBarrott
Mega Sage

I've created a Business Rule which should prevent the closure of project records if they are still project task which are not closed out. 

 

The error message is generating correctly but for some reason the Project Record will still move to Closed Complete even when using the setAbortAction call. 

 

Does anyone have any suggestions on this issue?

 

(function executeRule(current, previous /*null when async*/) 
{
	// Add your code here
	var gr = new GlideRecord('pm_project_task');
	var errorCount = 0;
	gr.addQuery('parent', current.sys_id); 
	gr.addQuery('state', '!=', 3); 
	gr.query();
	
	while(gr.next())
	{
		errorCount++;
		if(errorCount > 0)
			{
				gs.addErrorMessage('Cannot close Project with open tasks.');	
			}
		current.setAbortAction(true); //abort the record
	}
})(current, previous);

 

 

5 REPLIES 5

4b0d3
Giga Guru

Hello, try before br, with a low order, if async doesn't work.  
Or, I don't use project often & I forgot how they close.  You could add an onsubmit check prior to doing the action (paired with display BR if all in console).  Or hide the button itself with a display condition.

for other optimization, setting return limits can help.

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

	var gr = new GlideRecord('pm_project_task');
	gr.addQuery('parent', current.sys_id); 
	gr.addQuery('state', '!=', 3); 
        gr.setLimit(1);
	gr.query();
	
        if(gr.next())
	{
	      gs.addErrorMessage('Cannot close Project with open tasks.');	
	      current.setAbortAction(true); //abort the record
	}
})(current, previous);