Font Size:
Ask Joget AI

BeanShell List Data Store

The BeanShell List Data Store empowers users to configure lists using BeanShell code, allowing for versatile customization and dynamic data manipulation. This flexibility makes it a powerful tool for creating complex and highly customized data lists within Joget.

Configure BeanShell

To set up an external directory, go to Data, then select Data Store

Fields to Configure:

  • Select Source of Data (Data Store): Choose BeanShell.
  • Get Available Columns Script: Configure the columns of the list.
    Injected variables: plugin
  • Get Data Rows Script: Configure the rows and filters of the list.
    injected variables: plugin, dataList, filterQueryObjects, sort, desc, start & rows
  • Get Number of Total Data Rows Script: Configure the total number of rows to retrieve for the list.
  • Primary Key: Define the primary key column (default is id).

Usage Example

Sample App that utilizes the BeanShell Data Store to populate a list and apply a filter manually.

Get Available Columns Script:

import java.util.ArrayList;
import java.util.List;
import org.joget.apps.datalist.model.DataListColumn;

List columns = new ArrayList();
columns.add(new DataListColumn("id", "ID", true));
columns.add(new DataListColumn("name", "Name", true));
columns.add(new DataListColumn("information", "Information", true));
columns.add(new DataListColumn("category", "Category", true));

return columns.toArray(new DataListColumn[0]);

Get Data Rows Script:

import org.joget.apps.datalist.model.DataListCollection;
import org.joget.apps.form.model.FormRow;
import org.joget.apps.form.model.FormRowSet;
import org.joget.apps.datalist.model.DataListFilterQueryObject;
import java.util.regex.Pattern;
import java.util.ArrayList;
import java.util.List;

DataListCollection resultList = new DataListCollection();
FormRowSet rowSet = null;
FormRow fr = null;

// Data 1
fr = new FormRow();
fr.setProperty("id", "example-id-1");
fr.setProperty("name", "example name 1");
fr.setProperty("information", "example information 1");
fr.setProperty("category", "example category 1");

rowSet = new FormRowSet();
rowSet.add(fr);
resultList.addAll(rowSet);

// Data 2
fr = new FormRow();
fr.setProperty("id", "example-id-2");
fr.setProperty("name", "example name 2");
fr.setProperty("information", "example information 2");
fr.setProperty("category", "example category 2");

rowSet = new FormRowSet();
rowSet.add(fr);
resultList.addAll(rowSet);

// Data 3
fr = new FormRow();
fr.setProperty("id", "example-id-3");
fr.setProperty("name", "joget");
fr.setProperty("information", "example information 3");
fr.setProperty("category", "example category 3");

rowSet = new FormRowSet();
rowSet.add(fr);
resultList.addAll(rowSet);

DataListFilterQueryObject obj = new DataListFilterQueryObject();
boolean isFiltered = false;
Collection values = new ArrayList();
DataListCollection filteredResultList = new DataListCollection();
Collection uniqueRowKeys = new ArrayList(); // Collection to store unique row keys

System.out.println("START ----------------------------------------------");

for (int i = 0; i < filterQueryObjects.length; i++) {
    if (filterQueryObjects[i].getValues() != null && filterQueryObjects[i].getValues().length > 0) {
        values.addAll(Arrays.asList(filterQueryObjects[i].getValues()));
    }

    for (FormRow s : resultList) {
        String targetColumn = s.getProperty("name");
        String targetColumn2 = s.getProperty("information");
        System.out.println(s);

        for (String searchWord : values) {
            System.out.println(values);
            String searchWordReplaced = searchWord.replaceAll("%", "");
            if (targetColumn.contains(searchWordReplaced) || targetColumn2.contains(searchWordReplaced)) {
                // Create a unique key for each row
                String rowKey = s.getProperty("id") + "_" + searchWordReplaced;

                // Check if the key is not in the collection (i.e., the row is not added yet)
                if (!uniqueRowKeys.contains(rowKey)) {
                    FormRowSet rowSet = new FormRowSet();
                    rowSet.add(s);
                    filteredResultList.addAll(rowSet);
                    isFiltered = true;
                    uniqueRowKeys.add(rowKey); // Add the key to the collection
                    System.out.println("Row added to result");
                }
            }
        }
    }
}

if (isFiltered) {
    return filteredResultList;
}

if (values.size() > 0) {
    obj.setValues(values.toArray(new String[0]));
}

System.out.println("clear");

return resultList;

Get Number of Total Data Rows Script:

import org.joget.apps.datalist.model.DataListCollection;
import org.joget.apps.form.model.FormRow;
import org.joget.apps.form.model.FormRowSet;
import org.joget.apps.datalist.model.DataListFilterQueryObject;
import java.util.regex.Pattern;

DataListCollection resultList = new DataListCollection();
FormRowSet rowSet = null;
FormRow fr = null;

// Data 1
fr = new FormRow();
fr.setProperty("id", "example-id-1");
fr.setProperty("name", "example name 1");
fr.setProperty("information", "example information 1");
fr.setProperty("category", "example category 1");

rowSet = new FormRowSet();
rowSet.add(fr);
resultList.addAll(rowSet);

// Data 2
fr = new FormRow();
fr.setProperty("id", "example-id-2");
fr.setProperty("name", "example name 2");
fr.setProperty("information", "example information 2");
fr.setProperty("category", "example category 2");

rowSet = new FormRowSet();
rowSet.add(fr);
resultList.addAll(rowSet);

// Data 3
fr = new FormRow();
fr.setProperty("id", "example-id-3");
fr.setProperty("name", "joget");
fr.setProperty("information", "example information 3");
fr.setProperty("category", "example category 3");

rowSet = new FormRowSet();
rowSet.add(fr);
resultList.addAll(rowSet);

DataListFilterQueryObject obj = new DataListFilterQueryObject();
boolean isFiltered = false;
Collection values = new ArrayList();
DataListCollection filteredResultList = new DataListCollection();
Collection uniqueRowKeys = new ArrayList(); // Collection to store unique row keys

System.out.println("START ----------------------------------------------");

for (int i = 0; i < filterQueryObjects.length; i++) {
    if (filterQueryObjects[i].getValues() != null && filterQueryObjects[i].getValues().length > 0) {
        values.addAll(Arrays.asList(filterQueryObjects[i].getValues()));
    }

    for (FormRow s : resultList) {
        String targetColumn = s.getProperty("name");
        String targetColumn2 = s.getProperty("information");
        System.out.println(s);

        for (String searchWord : values) {
            System.out.println(values);
            String searchWordReplaced = searchWord.replaceAll("%", "");
            if (targetColumn.contains(searchWordReplaced) || targetColumn2.contains(searchWordReplaced)) {
                // Create a unique key for each row
                String rowKey = s.getProperty("id") + "_" + searchWordReplaced;

                // Check if the key is not in the collection (i.e., the row is not added yet)
                if (!uniqueRowKeys.contains(rowKey)) {
                    FormRowSet rowSet = new FormRowSet();
                    rowSet.add(s);
                    filteredResultList.addAll(rowSet);
                    isFiltered = true;
                    uniqueRowKeys.add(rowKey); // Add the key to the collection
                    System.out.println("Row added to result");
                }
            }
        }
    }
}

if (isFiltered) {
    return filteredResultList.size();
}

if (values.size() > 0) {
    obj.setValues(values.toArray(new String[0]));
}

System.out.println("clear");

return resultList.size();

Download the demo app for BeanShell List Data Store:

Created by Aadrian Last modified by Debanraj Ravindran on Apr 24, 2026