How to get Sum of related list field values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2022 10:45 AM
In project table i have a cost plan table as a related list where i need sum of all Total planned cost (highlighted in screenshot) values to be clubbed together and store it in a value for another calculation. can you guide me on this how to do it? This is something like need to get the related list field value but here if we have 3 related lists we need to get the sum of all 3 values if we add more it should sum it up and if we remove any of it should substract the value.
It looks something like this,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2022 11:19 AM
Hi,
Depends on when you want this calculation to happen, but this should help you. Tested and working on my PDI.
first line is the sys id of the project i want to calculate the total cost for
var project = '1bc72a0bdb8c881025c85a35dc9619d3';
var total = 0;
var costplanGr = new GlideRecord('cost_plan');
costplanGr.addQuery('task', project);
costplanGr.query();
while(costplanGr.next()){
total = total + costplanGr.cost_local_currency;
}
gs.log('Total cost of all cost plans in project: ' + total);
var totalCost = total; //Stored for use in other script.
Hope this helps.
Please mark my answer as Correct/Helpful based on impact
Regards,
Dan H