- 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:56 PM
Can you add a log like this and insert a new record to trigger this BR and now search in system logs for this message
gs.log("Did it work");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2016 02:03 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2016 02:55 PM
Since the initial question was already answered correctly here, I created another Discussion/Question for the second question that was asked here. It is a different issue than what was initially asked, so thought it best to create a new Discussion/Question. Link to New Discussion