How to populate text field using the Bean Shell Load Binder?
It's linked to my previous question : How to get data/value from 1 form/tab
Justin gave a proposal but his proposal doesn't match my request : we have >2000 end users - we can't let them to choose names by select box but only by hash variable " #currentUser.username#" . However, if I save a workflow "applicant" with value " #currentUser.username#", it can't find relation data from Form_B (Table B)
So I tried to use Bean Shell Load Binder to popluate data from Table B into Form C (ref to article Pre-populate Form Fields with Data from External Source) but it didin't work
Could anyone help me to check this app problem ? Thanks very much!!!
Bean Shell code is in Form C - Section 2
import org.joget.apps.app.service.*;
import org.joget.apps.form.model.*;
import org.joget.apps.form.service.*;
import java.sql.*;
import java.util.*;
import org.apache.commons.collections.SequencedHashMap;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.joget.apps.app.service.AppUtil;
import org.joget.apps.form.model.Element;
import org.joget.apps.form.model.FormData;
import org.joget.apps.form.model.FormRow;
import org.joget.apps.form.model.FormRowSet;
public FormRowSet getData() {
FormRowSet results = new FormRowSet();
results.setMultiRow(true);
try {
// retrieve connection from the default datasource
DataSource ds = (DataSource)AppUtil.getApplicationContext().getBean("setupDataSource");
con = ds.getConnection();
if(!con.isClosed()){
String pId = "#variable.applicant#";
String sql = "SELECT C_NAME, C_POSITION, C_FLIGHT_CLASS, C_BRANCH FROM app_fd_Table_B WHERE C_NAME= ?";
PreparedStatement stmt = con.prepareStatement(sql);
stmt.setString(1, pId);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
FormRow row = new FormRow();
row.put("aname", (rs.getString(1) != null)?rs.getString(1):"");
row.put("aposition", (rs.getString(2) != null)?rs.getString(2):"");
row.put("aflight", (rs.getString(3) != null)?rs.getString(3):"");
row.put("abranch", (rs.getString(4) != null)?rs.getString(4):"");
results.add(row);
}
}
} catch(Exception ex) {
System.err.println("Exception: " + ex.getMessage());
} finally {
try {
if(con != null)
con.close();
} catch(SQLException e) {}
}
}
return results;
APP_testFlightApp-1-20180522152356.jwa