Apply an Aggregate Function to a Calculated Field From a Child Business Object
When you want to aggregate a field in a parent business object based on a calculated field in a child business object, the calculated field won't show up as a Field to Aggregate field with the Aggregate from related business object data option in a field's Properties pane or the Create Aggregate Field option in the Fields tab. Using a calculated field with declarative field aggregation isn't supported, but you can get around this by storing the calculated value in the business object.
Consider a sample Shopping Cart scenario, where you have a Shopping Cart
business object with Cart Item
as its child business object. Assuming that Cart Item
has a field cartItemAmt
(calculated as Qty
* Unit Price
), you're trying to aggregate cartItemAmt
as the TotalAmount
in the Shopping Cart
business object.
The recommended approach for this requirement is to store the calculated value in the business object. You can do this by adding a trigger to the detail item that will catch any transaction and update the calculated field in the parent field (see Field Triggers).
This approach has the added advantage of speed; because the calculation isn't done at runtime, your page will load faster.