Validation after import tool for form fields
I am using import tool in post processing of the form . In the store data form i have add the field should have the value from the database data only . but on excel upload it is not checking this data .
I have added the below bean shell code for validation .
the record id in the bean shell is returning null .
but this is also not working
import java.sql.*;
import java.util.*;
import org.joget.apps.form.model.*;
import org.joget.apps.form.service.*;
import org.joget.apps.app.service.AppUtil;
import org.joget.apps.form.dao.FormDataDao;
import javax.sql.DataSource;
import org.joget.apps.app.service.AppUtil;
import org.joget.commons.util.LogUtil;
public boolean validate(Element element, FormData formData, String[] values) {
boolean result = true;
FormRowSet f = new FormRowSet();
f.setMultiRow(true);
FormDataDao formDatadao=(FormDataDao) AppUtil.getApplicationContext().getBean("formDataDao");
if (values != null) {
String recordId = "#requestParam.lo_number#";
DataSource ds = (DataSource)AppUtil.getApplicationContext().getBean("setupDataSource");
con = ds.getConnection();
if(!con.isClosed()){
System.out.println("Connected.....");
String sql = "SELECT select c_type from app_fd_types where c_type =?";
PreparedStatement stmt = con.prepareStatement(sql);
stmt.setString(1, recordId);
ResultSet rs = stmt.executeQuery();
int size = 0;
while (rs.next()) {
size++;
}
if (size == 0){
System.out.println("Not valid Type");
String id = FormUtil.getElementParameterName(element);
formData.addFormError(id, "Not valid Type");
con.close();
return false;
}
} //Connection
con.close();
return result;
}
}
//call validate method with injected variable
return validate(element, formData, values);