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

AshishKM
Kilo Patron
Kilo Patron

Hi @MBarrott 

Please update the BR "when to run condition" and code part.

AshishKMishra_0-1705514578302.png

 

(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();
	var pmTaskCount = gr.getRowCount();
       // check if there are open project task
        if(pmTaskCount > 0){
                      gs.addErrorMessage('Cannot close Project with open tasks.');	
                      current.setAbortAction(true); //abort the  action
        }
})(current, previous);

 

Test and share the update.

-Thanks,

AshishKMishra


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Hi @AshishKM 

 

The same issue is occuring, the project record gets closed out despite the call setAbortAction.

 

MBarrott_0-1705674796738.png

 

Check 1 )

Try to "Reload Page" , after updating the Project record, and check if its actually updated as "Close Complete". 

 

Check 2)

Seems like some other BR ( or logic ) running the pm_project table for closing and this BR is only checking the project task count and aborting the action , which is "the current BR in execution". but some other logic may still updating, u need to check some other BR ( if exist ).

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

bhanu27
Tera Expert

Use async BR