BR Not firing when field updated by system

Logan Calhoun
Tera Expert

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. 

10 REPLIES 10

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.

LoganCalhoun_4-1729694897150.png

 

 

Child Task - Planned end date is approaching deadline and status changes to Red.

LoganCalhoun_2-1729694760483.png

 

 

Top Task (Project) does not change to match the status of the child task.

LoganCalhoun_3-1729694832421.png