Bean Shell Code to retrieve text box value
Dear Expert,
I'm encountering some difficulties with Bean Shell Coding.
I have a field called currency (MYR/SGD). And, my select box(DOC ID) list should be based on currency.
Manage to get the list of document ID when i hardcode the currency in select statement.
However,I'm not sure of the code to retrieve the form field.
I try to use rows.get(0).getProperty("currency"), but, it doesn't seems working.
Can anyone help me?
Below is my code :
import org.joget.apps.form.model.*;
import org.joget.apps.form.service.*;
import java.sql.*;
import java.util.*;
Connection con = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jwdb?characterEncoding=UTF-8", "***", "**");
String fieldValue = "MYR"; //Attempt 1
//String fieldValue = rows.get(0).getProperty("currency"); //Attempt 2
if(!con.isClosed()){
PreparedStatement stmt = con.prepareStatement("select id,c_docUniqueCode from app_fd_doc_dtls where c_status = 'Completed' and c_username = '#currentUser.username#' and c_Currency=? order by 2");
stmt.setString(1, fieldValue); //added
ResultSet rs = stmt.executeQuery();
FormRowSet f = new FormRowSet();
f.setMultiRow(true);
FormRow vRow1 = new FormRow();
vRow1.put(FormUtil.PROPERTY_VALUE, "");
vRow1.put(FormUtil.PROPERTY_LABEL, "-- Select --");
f.add(vRow1);
while (rs.next()) {
FormRow vRow = new FormRow();
vRow.put(FormUtil.PROPERTY_VALUE, rs.getString(1));
vRow.put(FormUtil.PROPERTY_LABEL, rs.getString(2));
f.add(vRow);
}
System.out.println(stmt);
return f;
}
