Get Total of Two Duration Fields

michaelcory
Giga Expert

I have 3 fields on a Demand form (see screen shot below). Need to get the total of the Capital and Operational Resource Duration fields to display in the "Total Estimated Project Duration" field. I am using the BR shown below (Total Estimated Project Duration) but it is not working.   System Log shows that the BR is running.

From the screen shot below, the Total Capital Resource Duration and Total Operational Resource Duration get their values from 2 Business Rules that run on the Demand Table (See Related Lists below).   Below the Related LIsts is the BR that runs on the Demand table to get the Operational Resource Duration …The Capital BR is configured exactly the same.

find_real_file.png

BR =   Total Estimated Project Duration - Runs on Demand Table

function onBefore(current, previous) {

    //This function gets total duration by adding the Capital and Operational Resource durations

                              var timems = 0;

                              var dur = 0;

                              dur = current.u_tot_resource_duration_capital.getNumericValue();

                              timems += dur;

                              dur = current.u_tot_resource_duration_operational.getNumericValue();

                              timems += dur;

                              current.u_tot_est_project_duration.setDateNumericValue(timems);

                              //gs.log("Did it work");

}

Related Lists on Demand table

Related List — Capital Resources (u_dmn_resources_capital)

    1. Duration field (u_duration)
    2. Sum of Duration records added to Total Capital Resource Duration field (on parent Demand form)

Related List - Operational Resources (u_dmn_resources_operational)

    1. Duration field (u_duration)
    2. Sum of Duration records added to Total Operational Resource Duration field (on parent Demand form)

BR = Total Operational Resource Duration - Runs on Demand table - Gets the sum of all Duration fields in Operational Resources Related List

function onDisplay(current, g_scratchpad) {

    //This function queries the Related List records and adds the sum of durations to the Total Duration field on parent Demand

                              var total=0;

                              var grid = new GlideRecord('u_dmn_resources_operational'); //related list table name

                              grid.addQuery('u_demand',current.getValue('sys_id'));

                              grid.query();

                              while(grid.next()){

                                                              total+= grid.u_duration.dateNumericValue();

}

  1. current.u_tot_resource_duration_operational.setDateNumericValue(total);// Total Duration field on Demand form

}

1 ACCEPTED SOLUTION

Inactivate other two display business rules on the demand table. You only need one display business rule and the following script should go in there. I am putting everything in one business rule.




function onDisplay(current, g_scratchpad) {


  var total=0;


  var total1=0;


  var grid = new GlideRecord('u_dmn_resources_operational'); //related list table name


  grid.addQuery('u_demand',current.getValue('sys_id'));


  grid.query();


  while(grid.next()){


  total+= grid.u_duration.dateNumericValue();


  }


  current.u_tot_resource_duration_operational.setDateNumericValue(total);


  var grid1 = new GlideRecord('u_dmn_resources_capital'); //related list table name


  grid1.addQuery('u_demand',current.getValue('sys_id'));//reference field on related list table


  grid1.query();


  while(grid1.next()){


  total1+= grid1.u_duration.dateNumericValue();//duration field on related list table


  }


  current.u_tot_resource_duration_capital.setDateNumericValue(total1);//Total Cap Dur field on Demand Form


  current.u_tot_est_project_duration.setDateNumericValue(total+total1);


}


View solution in original post

25 REPLIES 25

Those fields are on the Demand table


There are a total of 10 Business Rules.   The first 7 in the list below run to get total resource cost and duration entered in the Capital and Operational related list tables.       find_real_file.png


Here's as schematic of the Demand form and Related Lists.   Trying to feed the Total fields on Demand from Related List records.


find_real_file.png


I know what is going on. Since the other 2 are display business rules. Change this before to display business rule. Add this script in there and you should be good to go



function onDisplay(current, g_scratchpad) {


  var timems = 0;


  timems += current.u_tot_resource_duration_capital.dateNumericValue();


  timems += current.u_tot_resource_duration_operational.dateNumericValue();


  current.u_tot_est_project_duration.setDateNumericValue(timems);


}


Ahh, getting something now.   It gets the Capital but not Operational.   Doesn't look like it's adding the Total Operational duration to the Total Estimated Project Dur.



find_real_file.png