Dropdown Selection with Multirow Data Store

This guide explains how to maintain a 1-to-many relationship (one feedback with multiple votes) between a parent table (feedback) and a child table (vote) using a dropdown select box instead of grids. You can utilize the Multiple Form Row with specific configurations using a grid form element.

Next, follow the steps to store and load data from a dropdown select box into a foreign table, similar to the Multirow Form Data Store.

  1. Place the code in the section's Load and Store Data Store Using Bean Shell Form Data Store.
  2. Add a dropdown select box to the section.
  3. Configurations for the Example:
    • Select Box ID: team_vote
    • Child Form ID: teamVote
    • Child Form Foreign Key: feedback
  4. Add the following code to load data from the dropdown select box into the foreign table:
    import org.joget.apps.form.model.FormRow;
    import org.joget.apps.form.model.FormRowSet;
    import org.joget.apps.app.service.AppUtil;
    import org.joget.plugin.base.PluginManager;
    import org.joget.apps.form.model.FormLoadBinder;
    import org.joget.workflow.model.service.WorkflowManager;
    
    String formDefId = "teamVote";  // Change this to the form ID used to load grid data
    String foreignKey = "feedback"; // Change this to the foreign key field ID
    
    // Reuse Multi Row Binder to load data
    PluginManager pluginManager = (PluginManager) AppUtil.getApplicationContext().getBean("pluginManager");
    WorkflowManager workflowManager = (WorkflowManager) AppUtil.getApplicationContext().getBean("workflowManager");
    FormLoadBinder binder = (FormLoadBinder) pluginManager.getPlugin("org.joget.plugin.enterprise.MultirowFormBinder");
    
    // Load from the grid table
    binder.setProperty("formDefId", formDefId);
    binder.setProperty("foreignKey", foreignKey);
    
    FormRowSet rows;
    rows = binder.load(null, "#requestParam.id#", null);
    
    String result = "";
    // Loop through records returned
    int count = 0;
    for (FormRow row : rows) {
        result += row.get("member") + ";";
        count++;
    }
    
    if(count > 1){
        result = result.substring(0, result.length() - 1);
    }
    
    FormRow row = new FormRow();
    row.setProperty("team_vote", result);
    
    FormRowSet rowSet = new FormRowSet();
    rowSet.add(row);
    
    return rowSet;
  5. Add the following code to store data from the dropdown select box into the foreign table:
    import org.joget.apps.form.model.FormRow;
    import org.joget.apps.form.model.FormRowSet;
    import org.joget.apps.app.service.AppUtil;
    import org.joget.plugin.base.PluginManager;
    import org.joget.apps.form.model.FormStoreBinder;
    import org.joget.workflow.model.service.WorkflowManager;
    import org.joget.apps.form.model.Element;
    import org.joget.apps.form.model.Form;
    import org.joget.apps.form.model.FormData;
    import org.joget.apps.form.service.FormUtil;
    
    String formDefId = "teamVote";  // Change this to the form ID used to load grid data
    String foreignKey = "feedback"; // Change this to the foreign key field ID
    
    // Reuse Multi Row Binder to load data
    PluginManager pluginManager = (PluginManager) AppUtil.getApplicationContext().getBean("pluginManager");
    WorkflowManager workflowManager = (WorkflowManager) AppUtil.getApplicationContext().getBean("workflowManager");
    FormStoreBinder binder = (FormStoreBinder) pluginManager.getPlugin("org.joget.plugin.enterprise.MultirowFormBinder");
    
    // Load from the grid table
    binder.setProperty("formDefId", formDefId);
    binder.setProperty("foreignKey", foreignKey);
    
    Form form = FormUtil.findRootForm(element);
    Element field = FormUtil.findElement("team_vote", form, formData);
    
    FormRow row = rows.get(0);
    FormRowSet f = new FormRowSet();
    f.setMultiRow(true);
    
    String vote = row.get("team_vote");
    String[] votes = vote.split(";");
    
    for(String v: votes){
        if(!v.isEmpty()){
            FormRow r = new FormRow ();
            r.setProperty("member", v);
            f.add(r);
        }
    }
    
    return binder.store(field, f, formData);
Created by Julieth Last modified by Aadrian on Dec 13, 2024