Using Groovy Aggregate Functions in ADF BC
- by Sireesha Pinninti
This article explains how groovy aggregate functions(sum, count, min, max and avg) can be used in ADF Business components and demonstrates how these can be used at entity and view level
Let's consider EMP and DEPT tables and an usecase to track number of employees in each department
Entity-Level
To use aggregate functions at entity level, we need to have association between entities representing master and child relationship and the destination accessor name is what we are going to use in our groovy
Syntax: <Accessor>.count(Groovyexpression)
- Note down the destination accessor name(EMP) in the association or AccessorAttribute name in source entity
- Add a transient attribute in source entity with persistent property set to false and provide the groovy expression in the syntax provided above
- Finally, Add newly added attribute to view object
View-Level
To use aggregate functions at view level, we need to have a view link between viewobjects representing master and child relationship and the destination accessor name is what we are going to use in our groovy
Syntax: <ViewLinkAccessor>.count(Groovyexpression)
- Note down the destination accessor name(EmpView) in the view link or viewLinkAccessor name in source view
- Add a transient attribute in view object and provide a groovy aggregate function count as a value to it in the syntax provided above
Now, If you run application module tester and execute DeptView / ViewLink, you should see employee count in EmpCount field
In similar way, one can use other groovy aggregate functions sum, avg, min and max.