Tuesday, March 26, 2013

How to sum column in View Object using Groovy

Use Case : 
we have 2 tables PayOrders  and  PayOrderTrans 
 we need to :  sum Credit column in PaymentOrderTrans table

  • First create New Attribute called CreditTotal 
  • Go to Default Value section
  • Choose Expression
  • Enter the following expression
         object.getRowSet().sum('Credit')

  What about the Null value ?   
     to avoid null value, you must modify the expression to
          object.getRowSet().sum('Credit != null ? Credit : 0 ')


1 comment: