1
0
-1

Hi Team,

I am using the bean shell for store binder for list grid. Below are the code. 


Issues: I am trying to get current form id values and store in the list grid form as a foreign key but unable to get the values.



//try {

import org.joget.apps.form.model.*;
import org.joget.apps.form.lib.*;
import org.joget.apps.form.service.*;
import java.sql.*;
import org.apache.commons.collections.SequencedHashMap;
import java.util.*;
import org.joget.commons.util.UuidGenerator;


import org.joget.apps.app.service.AppUtil;
import org.joget.apps.form.dao.FormDataDao;
import org.joget.apps.form.model.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.joget.commons.util.LogUtil;

public FormRowSet getGridRows() {
return rows ; // this will return the grid rows
}

public saveGridRows(FormRowSet rows) {

//LogUtil.info("Sample app - Form 1", ""+rows);
Connection con = null;
//try {
// retrieve connection from the default datasource
DataSource ds = (DataSource)AppUtil.getApplicationContext().getBean("setupDataSource");
con = ds.getConnection();
System.out.println("1112Hello Enter Connection ***********************");
// execute SQL query


if(!con.isClosed()){
System.out.println("Grid o Enter Connection ***********************");

String recordId = "#requestParam.id#";

// If you need to query data from different table(s) and process it before saving it to database,
// you can do it here

UuidGenerator uuid = UuidGenerator.getInstance();
System.out.println("Grid o Enter Connection2 ***********************"+ recordId);
Iterator i= rows.iterator(); // Iterating grid rows

while (i.hasNext()) {
FormRow row = (FormRow) i.next();
System.out.println("Grid o Enter Connection3 ***********************");
String packingslipno = row.get("packing_slipno"); // reading grid column value
String wo = row.get("work_orderno");
String partno = row.get("part_no");
String type = row.get("type");
String totalpackqty = row.get("total_packing_bundle_qty");
String paneldesc = row.get("panel_description");
String packcomments = row.get("packing_comments");
String pId = uuid.getUuid(); // generating Primary Key
String packid = row.get("id");
String wofk = row.get("wofk");
String qcfk = row.get("qcfk");


String insertSql = "INSERT INTO app_fd_ods_galva_sentstore (id,c_packing_slipno,c_work_orderno,c_part_no,c_type,c_total_packing_bundle_qty,c_panel_description,c_packing_comments,c_packing_id,c_wofk,c_qcfk) VALUES(?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement stmtInsert = con.prepareStatement(insertSql);
System.out.println("Grid o Enter Connection4 ***********************");
stmtInsert.setString(1, pId);
stmtInsert.setString(2, packingslipno);
stmtInsert.setString(3, wo);
stmtInsert.setString(4, partno);
stmtInsert.setString(5, type);
stmtInsert.setString(6, totalpackqty);
stmtInsert.setString(7, paneldesc);
stmtInsert.setString(8, packcomments);
stmtInsert.setString(9, packid);
stmtInsert.setString(10, wofk);
stmtInsert.setString(11, qcfk);
//stmtInsert.setString(12, qcfk);
stmtInsert.executeUpdate();
System.out.println("Grid o Enter Connection 5***********************");
//actual_quantity
//String updateSql="update app_fd_ods_wo_qcdetails set c_remaining_quantity=CAST(c_qc_quantity AS int)-(CAST(c_booked_quantity AS int)+CAST(? AS int)),c_booked_quantity=CAST(c_booked_quantity AS int)+CAST(? AS int),c_packing_status=? where id= ? and c_work_orderno= ? and c_part_no=?";
String updateSql="update app_fd_ods_packaging set c_galv_status=? where c_packing_slipno= ?";
PreparedStatement stmtUpdate = con.prepareStatement(updateSql);
stmtUpdate.setString(1, "Y");
stmtUpdate.setString(2, packingslipno);
//stmtUpdate.setString(3, wo);
// stmtUpdate.setString(4, partno);
stmtUpdate.executeUpdate();
System.out.println("Grid o Enter Update***********************");



}
} else {
System.out.println("Connection Problem");
}
con.close();
}

FormRowSet rows = getGridRows(); // getting the grid rows
saveGridRows(rows); // processing & storing the grid rows


//} catch (Exception e) {


//}



    CommentAdd your comment...

    2 answers

    1.  
      2
      1
      0

      Hi, what is the exception that you are getting? If it is for a list grid, why not just use the Multirow Form Binder as the store binder?

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

        Hi Anders,

        Thanks for the advise.

        But see my code there are two events fire one is the insert and other is the update the details. 

        How to manage the Multirow Form Binder. 

        I am using the list grid and only selected values store it is working fine , so I need after store the selected values 2nd time no need to display in the datalist that's a reason I am using the Beanshell scripts. Hope you understand my the situations.

        If any suggestion to handle from the Multirow form binder kindly let me know.


        Thanks 






          CommentAdd your comment...