Are you looking to show summary, average, or count across a set of records stored in your Visual Builder’s Business Objects? Since you don’t get direct SQL access to the underlying tables when working with business objects this can be a bit tricky. In this blog we’ll show how object functions can be used to overcome this limitation. For example, we are going to get the total salary for a list of employees that match a specific criteria.
Here is a video showing the complete end-to-end development steps.
In amny cases, aggregated fields in business objects can be used to summarize data in related objects, for example you can easily define an aggregated field at the department level summarizing the average salary for the employees working in that department. See for example this introduction video. But, if the query you are looking to execute is more complex and doesn’t depend on a direct relationship you can use an object function to do the aggregation.
Start by creating a dummy business objects on which we’ll define the function. Make sure there is one row in that business object – as we would need to refer to that row’s id whenever calling the function.
In the function itself you can access any business object in your application. Simply define a new view based on the business object name. Then you cand define a viewCriteria filter for the view. Note that we are using here the upper function to help us ignore upper/lowercase issues. Also note that we are using the proper way of creating, referencing, and setting values dynamically using bind variables. Using bind variables is one of our groovy best practices, and can prevent situations of SQL injection. Read the complete article here.
For regular information become a member in the Developer Partner Community please register here.