Business Rule is not aborting UI Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 08:11 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 10:07 AM
Hi @MBarrott
Please update the BR "when to run condition" and code part.
(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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 06:33 AM
Hi @AshishKM
The same issue is occuring, the project record gets closed out despite the call setAbortAction.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 10:48 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 11:11 AM
Use async BR