Question

I have created a tableA with fields ItemId, Quantity and Price(I have made the display method in tableA's method which returns the price of selected item). I dragged my display method in field groups and I'm using that field group in my form's grid

My question is how to calculate the total sum of selected item's prices and how to show the result in realEdit control?

Was it helpful?

Solution

I will assume you want the accumulated Quantity * Price for your lines.

The easiest way is to store the line amount field on table redundantly and compute it in the modifiedField method.

Then your total field could be a display method:

display Amount total()
{
     return (select sum(LineAmount) from TableA where ...).LineAmount;
}

Other solutions are possible such as a computed view field, but this one is a simple no-brainer.
The standard table SalesLine uses this approach as well albeit for other reasons.

That said even simple solutions come to short, if you have thousands of lines, in this case consider caching the total (on entry) then updating manually in write and delete methods.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top