You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Load

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;


Store

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){
    FormRow r = new FormRow();
    r.setProperty("member", v);
    f.add(r);    
}

return binder.store(field, f, formData);
  • No labels