Font Size:
Ask Joget AI

Pre-populate Form Select Box using BeanShell

Introduction

Pre-populating a form Select Box using BeanShell can significantly enhance the usability of your forms by providing users with dynamic, data-driven options. In Joget, this can be achieved using the Bean Shell Form Data Store to fetch and populate Select Box options from BeanShell script. 

How does it work?

To pre-populate a Select Box in your form using data from an external source, follow these steps:

  1. Go to the form where you want to add the pre-populated Select Box. Click the Select Box to open the properties panel.

  2. In the Or Load Data From, select Bean Shell.

  3. Configure BeanShell, enter your BeanShell script in the script area. This script should generate a FormRowSet with rows containing the data you want to display in the select list. For each FormRow added to the FormRowSet, include FormUtil.PROPERTY_VALUE and FormUtil.PROPERTY_LABEL fields.

    Example BeanShell script:

    import org.joget.apps.form.model.*;
    import org.joget.apps.form.service.*;
     
    public FormRowSet test() {
    FormRowSet f = new FormRowSet();
    f.setMultiRow(true);
     
    FormRow r1 = new FormRow();
    r1.put(FormUtil.PROPERTY_VALUE, "test1");
    r1.put(FormUtil.PROPERTY_LABEL, "tester1");
    f.add(r1);
     
    FormRow r2 = new FormRow();
    r2.put(FormUtil.PROPERTY_VALUE, "test2");
    r2.put(FormUtil.PROPERTY_LABEL, "tester2");
    f.add(r2);
     
    return f;
    }
     
    return test();

    In this script, FormUtil.PROPERTY_VALUE sets the value that will be sent when the form is submitted, and FormUtil.PROPERTY_LABEL sets the text displayed in the select list. You should replace the hardcoded values with dynamic data retrieved from your external source.

Related documentation

For more detailed information on using Bean Shell Form Data Store and related configurations, see the following resources:

Sample App

Download the sample App for Pre-populate Form Select Box from External Source
Created by Debanraj Ravindran Last modified by Nur Baizura Badrul Sham on Jul 17, 2026