Shay Shmeltzer's Oracle Development Tools Tips

Group Functions on Business Objects in Visual Builder

Shay Shmeltzer
Director of Product Management - Oracle

In this blog I'll show you how to use functions such as Sum, Avg and Count on the data you store in business objects in Visual Builder. While you don't have direct way to write a sql statement to get this data, the ability to create object functions gives you access to similar functionality.

Object functions leverage groovy to interact with the business objects. I covered an intro to this topic in the blog entry about service methods for BOs, and we have a reference book that explains how to work with business objects and groovy. If you'll look at this chapter in the book you'll find out that there are many methods you can invoke on a viewObject - which maps to a BO. These include the ability to perform CRUD operations, add where and sort clauses to queries, and also to use group functions.

In the video demo below I use the following code in an object function:

def vo = newView('Employees');
return vo.avg("salary");

This simply returns the average of the salary field across all employees. The second line prints the maximum value in the id field across employees in the log of the business objects - print is a useful step when debugging your groovy code.

Once you have the function in place it is exposed as a POST type of REST operation on the business object. You can call it from action chains in Visual Builder - but remember to pass in a content-type of application/vnd.oracle.adf.action+json (or it will error with 415).

As a small added bonus, in the second part of the video (from about 5:00) I show how to add a reference line to a chart in your VB app, and base that line on the value we got from the function.

Join the discussion

Comments ( 2 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.