1
0
-1

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;
}

 

    CommentAdd your comment...

    3 answers

    1.  
      1
      0
      -1

      Hi Andrew,

      I manage to solve the problem. Custom HTML should be placed on top of 'document no dropdown' field. 

      I manage to do it for currency2 as hidden field as well.

      Thank you very much for the suggestion.

        CommentAdd your comment...
      1.  
        1
        0
        -1

        Hi Andrew,

         

        Thank you for the suggestion. But, the value doesn't change based on my text box.

        Let me explain further.

        1) I have 3 documents, 2 documents for MYR(XXX092,XXX093) and 1(XXX094) Document for SGD.

        2) The currency selector is in main form

        3) I have a form grid and the document id selector is over here. Therefore, I have created a Custom HTML to hold the currency field value from parent form. And, the currency field in child form should be a hidden field. (For now, I'm doing it as textbox to see if the dropdown works). let's call it currency2.

        4) For my document id dropdown, i have checked the 'Use AJAX for cascade options?' option and added the field id to control to currency2.

        5)      a) currency2 'Value' property is null. Therefore, CustomHTML set the value based on the parent form value. However, the dropdown doesn't work. 

                         

              b) currency2 'value' property set to SGD. I selected MYR in main form, Currency2 field changed to MYR. But, the dropdown showing SGD document ID.

                  

         

          CommentAdd your comment...
        1.  
          1
          0
          -1

          Hi Shubana

          Can I suggest you give JDBC Options Binder Plugin a try?

          Using this plugin, you can easily key in the SQL Select Query to populate the selectbox.

          Example: 

          SELECT id, c_CountryName FROM app_fd_country

           

          Related SQL JDBC binders:

            CommentAdd your comment...