'Calculated' Data Type for Entity Attributes

On our radar
I'd like to see the ability to declare runtime calculated entity attributes to simplify app design and improve application robustness and consistency.  The attributes would not be created or stored in the database but would be available in webscreens, actions etc like a 'normal' attribute.  It would be good it they could be simple calculations based on entity fields from the same entity, aggregates from related child entities or based on result of an action.

e.g. the classic Invoice and LineItems

Each line item may have a caclutated attribute "LineTotal" which is a simple LineQty * LinePrice calculation

The Invoice would have an InvoiceTotal which is the the Sum Of "LineQty * LinePrice" from the related LineItems entity

There may be more complicated fields such as tax calculations that are calculated in an action. e.g. for a combination of state and federal taxes dependant on which state the invoice customer is from.
Created on 18 Apr 2014
Comments (5)
I've wanted this for so long!

We work around it by doing the calculation in our data access layer, on Insert/Update. But it would be great if this was built in!

You could get this functionality if Outsystems implemented database views as described here - https://www.outsystems.com/ideas/1019/native-support-for-database-views .  You'd (hopefully) be able to do any functions that a database view would provide including the calculations you are looking for.

So you declare entity attributes for totals etc. and save the values to the database?


Thanks for your input but I don't really see views as the solution (although views would be a handy additition to the platform). I believe where possible logic should be declared once only.  Multiple views for an entity means declaring rules multiple times which is no different to the current situation.

Gavin -


'Calculated Attributes' inside Entity definition would be powerful. As it also would be only for sql select statement (no update/insert), maybe this could be achieved if OutSystems support a new property aiming this new kind of entity attributes, called 'SQL Expression', receiving as value an "inner sql query", and then using his value to build the database sql queries.
1) Something link this:
  - Name: ...
  - Data Type: ...
  - Length: ...
  - SQL Expression: "(Entity1.Attr2 + Entity1.Attr3) as CalculatedAttr1"
The final sql will be builded like this (replacing with the property value):
select ...., CalculatedAttr1.SQLExpression, .... from .... where ....
2) Another example, and more sophisticated Calculated Attribute:
  - SQL Expression: "(select ... from ... where ...) as CalculatedAttrX"
The final sql will be builded with the same logic:
select ...., CalculatedAttrX.SQLExpression, .... from .... where ....
Sorry if I misunderstood, but perhaps this is a possible solution.