ajax cascade doesnot show form element

Confluence User - 19 Jul, 2023

Hi There 

I have a requirement to show the list of users from the joget user directory those who are not present between the selected scheduled start date and end date in a table so to achieve this i have used beanshell plugin and below is the code but i am unable to get the scheduled start date and end date value upon cascade it says undefined argument element. 


Please note: All the namespaces are included 



public FormRowSet load(Element element,FormData formData,String[] values) {

    FormRowSet rows = new FormRowSet();
    ExtDirectoryManager directoryManager = (ExtDirectoryManager) AppUtil.getApplicationContext().getBean("directoryManager");
    Form form = FormUtil.findRootForm(element);
    Element field1 = FormUtil.findElement("scheduleStart", form, formData);
    Element field2 = FormUtil.findElement("scheduleEnd", form, formData);
    String[] compareValues = FormUtil.getElementPropertyValues(field1, formData);
    String[] compareValues2 = FormUtil.getElementPropertyValues(field2, formData);
    DataSource ds = (DataSource)AppUtil.getApplicationContext().getBean("setupDataSource");
    Connection conn = ds.getConnection();
    ArrayList users = new ArrayList();
    PreparedStatement statement = null;
    ResultSet resultSet = null;
    PreparedStatement statement1 = null;
    ResultSet resultSet1 = null;
try{
 
    
     String query = "SELECT c_Person  FROM app_fd_db_Tasks WHERE  ((c_scheduleStart <= ? AND c_scheduleEnd >= ?) OR (c_scheduleStart <= ? AND c_scheduleEnd >= ?))";
        statement = connection.prepareStatement(query);
    statement.setString(1, compareValues2[0]);
        statement.setString(2, compareValues[0]);
        statement.setString(3, compareValues[0]);
        statement.setString(4, compareValues2[0]);
     resultSet = statement.executeQuery();
    while (resultSet.next()){
 users.add(resultSet.getString("c_Person"));

}
}
catch (SQLException e) {
           LogUtil.info("",e.getMessage());
        }
finally {
        // Close database resources
        try {
            if (resultSet != null) {
                resultSet.close();
            }
            if (statement != null) {
                statement.close();
            }
           
        } catch (SQLException e) {
           LogUtil.info("",e.getMessage());
        }
    } 


try{

    String query = "SELECT username,firstName,lastName  FROM dir_user";
    statement1 = connection.prepareStatement(query);
    resultSet1 = statement1.executeQuery();
    while (resultSet.next()){
    if(!users.contains(resultSet.getString("username"))){
    FormRow option = new FormRow();
        option.setProperty(FormUtil.PROPERTY_VALUE, resultSet.getString("username"));
        option.setProperty(FormUtil.PROPERTY_LABEL, resultSet.getString("firstName") + " " + resultSet.getString("lastName"));
        rows.add(option);
}
}
}
catch (SQLException e) {
           LogUtil.info("",e.getMessage());
        }
finally {
        // Close database resources
        try {
            if (resultSet1 != null) {
                resultSet1.close();
            }
            if (statement1 != null) {
                statement1.close();
            }
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
           LogUtil.info("",e.getMessage());
        }
    } 
     
    return rows;
}
 
//call load method with injected variable
return load(element, formData,values);

ERROR 19 Jul 2023 13:02:30 org.joget.apps.form.lib.BeanShellFormBinder - Error executing script
5143bsh.EvalError: Sourced file: inline evaluation of: ``import java.util.Collection; import java.util.HashMap; import java.util.Map; . . . '' : Undefined argument: element


forms;ajaxcascade;beanshell

1


25 Jul, 2023
confluenceUser
confluenceUser

Hi, the script error says "Undefined argument: element" so it appears that the "element" variable is not available. Where are you using this plugin? Try checking to see if the plugin is used in the appropriate place in order for certain variables to be properly injected.

RELATED QUESTIONS

Your answer


To answer a question you'll need an account.

Print