1
0
-1

I have 2 forms:

Form1 - aas_routes - Parent Form - Saving Route information

Form2 - routes_notes - Child Form - Saving every action performed on the above form

 

In my scenario, I am using a Grid in the parent form to populate the "Route_notes" data to show the actions/audit notes performed on the parent form by different Users in each activity of the Workflow.

 

I am using the following Bean Shell Code:

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.DecimalFormat;
import javax.sql.DataSource;
import org.joget.apps.app.service.AppUtil;
import org.joget.apps.form.model.FormRow;
import org.joget.apps.form.model.FormRowSet;
import org.joget.apps.form.service.FormUtil;
import org.joget.apps.form.model.*;
import org.joget.apps.form.service.*;
import java.sql.*;
import org.apache.commons.collections.SequencedHashMap;
import java.util.*;

public FormRowSet getgridData() {
FormRowSet fgrid = new FormRowSet();
fgrid.setMultiRow(true);
try {
DataSource ds = (DataSource)AppUtil.getApplicationContext().getBean("setupDataSource");
con = ds.getConnection();
if(!con.isClosed()){
String routeId = "#form.aas_routes.id#";
String sql = "Select c_name,datecreated,c_Role,c_status,c_notes from APP_FD_ROUTE_NOTE where c_request_id1='"+routeId+"' order by datecreated ASC";
PreparedStatement stmt = con.prepareStatement(sql);
ResultSet grs = stmt.executeQuery();
while (grs.next()) {
FormRow gr1 = new FormRow();
gr1.put("gridColumn1", grs.getString(1));
gr1.put("gridColumn2", grs.getString(2));
gr1.put("gridColumn3", grs.getString(3));
gr1.put("gridColumn4", grs.getString(4));
gr1.put("gridColumn5", grs.getString(5));
fgrid.add(gr1);
}
}
} catch(Exception ex) {
System.err.println("Exception: " + ex.getMessage());
} finally {
try {
if(con != null) con.close();
} catch(SQLException e) {}
}
return fgrid;
}
return getgridData();

 

I have selected following the Grid to be shown as mentioned below:

 

Options

 

ValueLabel 
    
    
    
    
    

 

I am not getting any error in the Logs. However, I do not see any value being populated in the Grid from the database table.

Could you please let me know where I am getting wrong in my configuration?

 

    CommentAdd your comment...

    2 answers

    1.  
      1
      0
      -1

      In Grid > Options > Value, you are declaring the column ID. Make sure that all the IDs matches the FormRow.put("ID","value") in your code.

      1. Rahul Katara

        Thanks Bastiana, It did work :)

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

      Try to inspect this block of code. Put a System.out.println() in the while loop to check. Maybe there's no data returned at all.

      while (grs.next()) {
      FormRow gr1 = new FormRow();
      gr1.put("gridColumn1", grs.getString(1));
      gr1.put("gridColumn2", grs.getString(2));
      gr1.put("gridColumn3", grs.getString(3));
      gr1.put("gridColumn4", grs.getString(4));
      gr1.put("gridColumn5", grs.getString(5));
      fgrid.add(gr1);
      }
      1. Rahul Katara

        Hi, I have tested the code using the print statement and the sql query is returning values for all the five fields used in my query: I want to populate them these five fields in my grid as follows: Do I need to add any code for populating the headers? Name Date Role Actions Notes andy Jun 19, 2015 4:32:01 PM Support Analyst Send for IM Approval clark Jun 22, 2015 2:49:40 PM Integration Manager Form Assigned

      CommentAdd your comment...