- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2016 02:49 PM
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.
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)
Related List - Operational Resources (u_dmn_resources_operational)
|
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(); }
} |
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2016 09:42 PM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2016 08:02 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2016 08:58 PM
Can you share the code of Capital Dur BR ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2016 09:23 PM
BR = Total Capital Resource Duration - Runs on Demand table
function onDisplay(current, g_scratchpad) {
var total=0;
var grid = new GlideRecord('u_dmn_resources_capital'); //related list table name
grid.addQuery('u_demand',current.getValue('sys_id'));//reference field on related list table
grid.query();
while(grid.next()){
total+= grid.u_duration.dateNumericValue();//duration field on related list table
}
current.u_tot_resource_duration_capital.setDateNumericValue(total);//Total Cap Dur field on Demand Form

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2016 09:42 PM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2016 10:17 PM
Works perfectly Abhinay! Many thanks for your time, patience, and expertise. I will mark the answer Correct.