Pre-populate Form Select List from External Source

Introduction

Pre-populating a form select list from an external source 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 list options from an external database or other data sources. 

How does it work?

To pre-populate a select list 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 list. Click the select field and then click Edit.

  2. In the Choose Options Data Store menu, select Bean Shell Form Data Store from the Options Data Store select field.

  3. Configure Bean Shell Form Data Store, enter your Bean Shell script in the configuration 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 Bean Shell 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.

For more information on how to connect to a database source, see the example code within Pre-populate Form Fields with Data from External Source

Related documentation

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

Created by Julieth Last modified by Aadrian on Dec 13, 2024