BR Not firing when field updated by system
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 06:38 AM
Hi All,
I am working in PPM and trying to update the status (green, yellow, red) of the top task depending on the status of all the child task.
I've created a business rule to run when the 'status' changes of any task on the pm_project_task table.
(function executeRule(current, previous /*null when async*/ ) {
var topTask = new GlideRecord('pm_project');
if(topTask.get(current.top_task)){
var totalTask = 0;
var greenTask = 0;
var yellowTask = 0;
var redTask = 0;
var allTsk = new GlideRecord('pm_project_task');
allTsk.addQuery('top_task', topTask.sys_id);
allTsk.addEncodedQuery('numberSTARTSWITHPRJT');
allTsk.query();
while(allTsk.next()){
totalTask++;
if (allTsk.status == 'green') {
greenTask++;
} else if (allTsk.status == 'yellow') {
yellowTask++;
} else if (allTsk.status == 'red') {
redTask++;
}
}
if (redTask > 0) {
topTask.setDisplayValue('status', "red");
} else if (redTask == 0 && yellowTask > 0) {
topTask.setDisplayValue('status', "yellow");
} else {
topTask.setDisplayValue('status', "green");
};
topTask.update();
}
})(current, previous);
This was tested in a background script and works if I change the status of the child task and then run the background script. It will also run if I click on the status and change it manually.
The problem is I want to this run when the planned end date approaches the planned start date. If the planned start date is >3 days out the status is green, >1 day it is yellow, and <1 day it would be red. The changing of the planned end date will change the status of the child task but the business rule will not run.
I have attempted to change the WHEN to before and after but nothing seems to affect it, same with the order. It doesn't look like anything else should be stopping this from running in the system logs as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 06:46 AM
Hi,
Maybe Try to run this on a flow or scheduled job. BR needs a trigger which will run only when there is a change to the record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 06:53 AM
Hi Anurag,
I will give this a try.
Changing the planned end date does change the status. Shouldn't this still fire the BR if it is changing on the table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 07:14 AM - edited 10-23-2024 07:15 AM
If the state changes then the BR would fire.
Even if only the planned end date is changed and REcord is saved BR would fire.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 07:25 AM
That is the problem I am running into.
If I change 'status' of child task manually and select 'save'. The business rule will run and change the top task to the same status.
If the planned end date is approaching and the 'status' changes the business rule does not run.