- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2016 12:19 PM
I have a Related List on the Demand form. The related list table has a Duration field. There may be 1 or several records created in the Related List with Duration values. I need to get the Total of all duration values in the records from the Related List and add to a Total field on the Parent (Demand form). I was provided a great Community solution for how to do this with Total Costs (link), but am struggling with the duration format. Below is the business rule solution that was provided and works for the Cost field totals. I tried applying the business rule to the Related List table that has the duration field. I modified the script by adding getNumericValue to query duration and setDateNumericValue to the value set on the Demand record,but doesn't work. Tried various other business rules to no avail. Any suggestions?
(function onAfter(current, previous /*null when async*/) {
var pd = current.u_demand; //reference field to parent demand
var query = 0;
var grid = new GlideRecord('u_dmn_resources_capital'); //related list table name
grid.addQuery('u_demand', pd);
grid.query();
while(grid.next()){
query += grid.u_duration.getNumericValue();
}
var gr = new GlideRecord('dmn_demand');
gr.addQuery('sys_id', pd);
gr.query();
while(gr.next()){
gr.setDateNumericValue('u_tot_resource_duration_capital', query);//Duration Total on Parent Demand
gr.update();
}
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2016 12:25 PM
You need a display business rule on the demand table for this. And put this code in there
var total=0;
var grid = new GlideRecord('u_dmn_resources_capital'); //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_capital.setDateNumericValue(total);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2016 01:01 PM
Everything looks ok. Are you sure you changed the duration values to trigger the BR?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2016 01:16 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2016 01:12 PM
Please mark my response as correct.
If you are viewing this from the community inbox you will not see the correct answer button. You need to open the thread directly and you will see a correct answer button with red star. Please review this How To Mark Answers Correct From Community Inbox

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2016 01:33 PM
Can you insert a log statement in the business rule and see if the business rule is triggered at all?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2016 01:54 PM