Can I calculate the sum of a formula field of a related obje

Posted by Ruben Dröge on 22-Apr-2016 02:17

I have two objects A & B, where the relationship is 1:N
object B has a formula field that calculates hours worked based on a start and end time.
In object A I want to create a formula field that calculates the sum of the 'Hours_worked' field of object B.

This doesn't seem to work though when using:

#CALC_SUM.R32206( Hours_worked )

Is there another way to get this sorted?

All Replies

Posted by Aede Hoekstra on 22-Apr-2016 07:04

You can't get the sum of a calculated field. I've solved some sort of problem in the following way:

Create a trigger on object A which calculates the field based on the related records.

var numberOfRatings = #CALC_COUNT.R820158(Rating_Number);

var sumRatings = #CALC_SUM.R820158(Rating_Number);

return numberOfRatings / sumRatings;

And place a trigger on object B which runs the trigger on object A at update/edit/delete

Posted by Ruben Dröge on 22-Apr-2016 08:10

Do I understand correctly that the field in object B cannot be a calculated field in this scenario?

So I have my calculated field in object B (hours_worked) and I first have to get that value into a normal field (by using a trigger to update the field value) in object B?

After that I should be able to calculate the sum of the 'normal field' of object B in my formula field in object A right?

Posted by Aede Hoekstra on 22-Apr-2016 09:11

Calculated fields aren't stored in the Rollbase db. They are more used for displaying on object level, they also can't be used for sorting in views. I've also once tried your approach with expression fields (because these are stored in the database) but those fields are only updated when the record is updated. So that's why I've used the approach as described as above.

This thread is closed