Вы находитесь на странице: 1из 5

9/1/2019 Service Methods for Business Objects in Visual Builder | Oracle Visual Builder Cloud Service Blog

Oracle Visual Builder Cloud Service Blog


 MENU

Oracle Visual Builder Cloud Service Blog

The Visual Builder Cloud Service Blog

Try Oracle Cloud Platform


For Free

ORACLE VISUAL BUILDER CLOUD SERVICE

May 21, 2019

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

https://blogs.oracle.com/vbcs/service-methods-for-business-objects-in-visual-builder 1/5
9/1/2019 Service Methods for Business Objects in Visual Builder | Oracle Visual Builder Cloud Service Blog

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.

https://blogs.oracle.com/vbcs/service-methods-for-business-objects-in-visual-builder 2/5
9/1/2019 Service Methods for Business Objects in Visual Builder | Oracle Visual Builder Cloud Service Blog

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.

Creating Service Object Functions for Business Objects

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

1 def vo = newView('Department')
2 vo.appendViewCriteria("department = '"+dname+"'")
3 vo.executeQuery()
4 if (!vo.hasNext()){
5 r = vo.createRow()
6 r.maxSalary=salary;
7 r.department=dname;
8 vo.insertRow(r)
9 }
10 while (vo.hasNext()) {
11 def r = vo.next();
12 r.maxSalary = salary;
13 }

Line 1 gets us a pointer to our business object

https://blogs.oracle.com/vbcs/service-methods-for-business-objects-in-visual-builder 3/5
9/1/2019 Service Methods for Business Objects in Visual Builder | Oracle Visual Builder Cloud Service Blog

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.

Be the first to comment

Comments ( 0 )

Recent Content

ORACLE VISUAL BUILDER CLOUD ORACLE VISUAL BUILDER CLOUD


SERVICE SERVICE
Complex Queries in Visual Builder Adventures in Mutation - Adding
Rows to a Table or ListView in Oracle
https://blogs.oracle.com/vbcs/service-methods-for-business-objects-in-visual-builder 4/5
9/1/2019 Service Methods for Business Objects in Visual Builder | Oracle Visual Builder Cloud Service Blog

Often, you have to filter a data set Visual Builder


based on multiple search criteria
like in the above image. In this
case, you want to only create...

Site Map Legal Notices Terms of Use Privacy Cookie Preferences Ad Choices

Oracle Content Marketing Login

https://blogs.oracle.com/vbcs/service-methods-for-business-objects-in-visual-builder 5/5

Вам также может понравиться