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

If the planned end date is approaching  -> This case can be handled by a job or a flow that you run daily/ Scan all items that 'fit the filter' and compare then and run the job. 

-Anurag

I want the status to change on the fly and not wait for a schedule job to run. Our PMO will want status reports to be updated to date all the time. If he is looking at a project and the status is red but in reality, it is green because the schedule job has not run yet it will not work.

I don't believe Scheduled jobs or Flows will be of use in our business work case. Need this to update on the fly when the status is changed from planned end date.

- Logan

Logan Calhoun
Tera Expert

Correcting a typo. I want the rule to run when the current date approaches the planned end date and the status changes automatically. 

 

Rule only runs when the status is changed manually or when I run the background script. Rule Doesn't run when the current date approaches the planned end date and the status changes.

Rule only runs when the status is changed manually or when I run the background script. Rule Doesn't run when the current date approaches the planned end date and the status changes. --> This is right.


-Anurag