Saturday 20 April 2013

ADF: Calculating total sum of Salary of all the employees in a Department using Groovy expression.

If there is a condition in which you have to calculate the sumtotal of a VO field in ADF (like if you want to calculate the sum of salary of all the employees of a Department) , then better of all option is to use groovy expression to calculate the sum.
Here is an application which is used to calculate the sum of salary of all the employees of a given department.

  1. Create a new ADF application and create database connection with HR Schema. Generate the Business components. Here am using two tables ie Employee and Departments.
  2. Now create a ViewLink between Department and Employee using DepartmentId as foreign key.

  3. Use the Accessor to get the salary from the employee table to department table.
  4. Then create a transient variable in the DepartmentVO, and then assign value to it using the expression

    EmpVO.sum("SalTot");
  5. Here is an screen shot. The name 'EmpVO' is the name of the Accessor of the Employee table in the deptToEmpViewLink.
  6. Then run the AM to see the Application.
  7. You can find the ADF application at Groovy.rar

No comments:

Post a Comment