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 07:49 AM
Correct -
I am trying to figure out why this is. The table field 'status' still changes when the current date approaches the end date (In my mind this would still cause the business rule to fire as it meets the conditions). I am looking for guidance as to why this is. Either the BR isn't run because the change of status is not an 'update' when the field changes due to current date approaching or something else.
Child Task - Status Yellow. Planned end date is in 3 Days.
Child Task - Planned end date is approaching deadline and status changes to Red.
Top Task (Project) does not change to match the status of the child task.