Visual Builder makes it very simple to invoke REST services from your user interface, but did you know that you can also call the same services from the business objects layers? There are cases where you need to invoke external logic or get external data directly from your application's backend data layer.

Business Objects (BO) can act as the logic layer on top of your data in Visual Builder applications. As such, you might run into situations where that layer needs to interact with external systems through REST interfaces. The BO layer can leverage the same services defined in your VB app – and call them from custom logic you write using Groovy. This can be as part of a business object trigger (insert/update/delete event), or object functions. Visual Builder's Groovy reference book has a section covering how to interact with services in details.

In the demo below you can see the basics of invoking a service from a trigger on a business object:

When you define a service, take note of the service name, the id of the endpoint you need to invoke, and the exact names of each of the parameters you need to pass to the service. Each one of those will be something your groovy code will reference. Once you have the info you can use a piece of code similar to this:

import oracle.adf.model.connection.rest.exception.RestConnectionException
import oracle.jbo.ValidationException
try{
def svc = newService('Credits')
svc.queryParams['api_key'] = 'e3956afc22c88'
svc.pathParams.movie_id = dbId
def results = svc.getMovieMovie_idCredits()
println(results);
println(results.cast[0].name);
leadActor = results.cast[0].name
}
catch (RestConnectionException rcex) {
  throw new ValidationException("Can't find actor");
} 

To help you debug issues in your code, turn on logging on the BO layer, and use println statements to output important information into the log.