The Visual Builder Cloud Service Blog

Service Methods for Business Objects in Visual Builder

Shay Shmeltzer
Director of Product Management - Oracle

In a previous blog I showed you how to create an object function for a business object to allow you to expose specific functionality on a specific row. This blog is a little variation on this capability showing you how to create service methods in your data layer that are not related to a specific row. 

This is based on a use case a customer had where they would get data for a record in a table, if the row already exists in the table they need to update it. If it doesn't exist they need to create a new row with the data. The REST API provided by the Visual Builder business objects supports this use case as long as you have the id of the record you want to update. This is done with the upsert option for a POST call - see the information about this combined insert/update operation here.

But the data that the customer got didn't have the id of the record they would need to update. Instead they had the information about another field in the object. To resolve this we can create a function in the BO layer that will search the set of records for a specific value in a specific field, and then update that record if the value is found, or insert a record if it doesn't exist.

The tricky part is that object functions work on a specific record in a BO (the id of that record is part of the path to that REST endpoint). In our case, we don't have a row to work on. Instead, we are going to create a dummy business object, with a single row in it. Then we'll create the function on this business object, always invoking it with the id of the row that is in there. This technique could be useful for any generic function you need in you BO layer that doesn't directly relate to a specific row.

The function itself is written in Groovy, the programming language used by the Visual Builder business objects layer. In the video you'll see how we use various methods available on BOs in groovy (such as methods to query, add filter condition, and insert new records). You can learn more about these and other methods in our new Groovy for Visual Builder Reference Book.

In the video below you'll see how to add such a function and how to call it from the VB user interface. Note that these functions are also callable from other tools through simple REST calls.


For those interested in the specific code used in the sample it is:

def vo = newView('Department')
vo.appendViewCriteria("department = '"+dname+"'")
if (!vo.hasNext()){
  r = vo.createRow()
while (vo.hasNext()) {
  def r = vo.next();
  r.maxSalary = salary;


Line 1 gets us a pointer to our business object

Line 2 adds a "where" clause to the query associated with our instance

Line 3 execute the query with this where clause

in the If section starting at line 4 we take the case where no records where found, create a new row, populate the data in the fields in that row, and then insert it into the business object.

In the while loop we handle the case where a record (or more) were found, and update that row with the new value.

One more tip - when you want to invoke the function from outside Visual Builder - remember to pass in the content-type of application/vnd.oracle.adf.action+json

Join the discussion

Comments ( 4 )
  • Sandeep Wednesday, December 4, 2019

    I have a requirement to insert multiple records in child and grand child business object. Can you please suggest how this can be done?
  • Shay Shmeltzer Wednesday, December 4, 2019
    Sandeep - you should post these type of questions on our forum:
    You can look into the batch REST support for BOs:
  • Sriram Thursday, January 14, 2021
    I have a requirement to build/store role-feature-permission matrix which I can design using business objects. However, I would like to know if there is capability to have an intermediate code that can compute the features-permissions list for a given role and return the result in a alternate format.

    For example, on a page for a given feature-entitlement, I want the result to know if it is enabled (true/false). How can I achieve this?
  • Shay Shmeltzer Sunday, January 31, 2021
    I'm not sure I understand your use case - it might be better if ask and provide more info on our forum: https://cloudcustomerconnect.oracle.com/resources/e610f4723c/summary
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.