How to populate a select box field from a database using Groovy

A good practice while developing processes is to store business data in an external business database and retrieve them only when needed. A good question is: How do I retrieve this information from my forms?

Here’s a quick tutorial which explains how to retrieve the information from an external database, and display it as the initial value of a select box field in a form. You can find the process used as an example here.

Create a process with a human task and one form to interact with.

Add an entry pageflow form on the task Display data.

In this form, use a widget to add a select box field.

Click on the select box widget, then on the General tab and Data pane. In the available value field, use this script:

import groovy.sql.Sql;
def result =
Sql sql = providedscripts.BonitaSql.newInstance(url,username,password,jdbcdriver)
sql.eachRow ‘select * from USERS;’, { result += it.name }
sql.close()
result

This script will create a list to store the usernames that are returned. Then, it opens the SQL connection to query the table and add each name to the list. Finally, it returns the result.

At the execution, you’ll get this: