Hello Jogetor guys,
I wrote beanshell script in beanshell tool plug-in. my question is how can call it in my form.
beanshell
import java.util.*;
import java.sql.*;
import javax.sql.DataSource;
import java.io.*;
Connection conn = null;
PreparedStatement stmt = null;
try
{
String userName = "root";
String password = "";
String url = "jdbc:mysql://localhost:3307/jwdb?characterEncoding=UTF-8";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
if(!conn.isClosed())
{
String sql = "SELECT Count(*) FROM app_fd_application WHERE app_fd_application.c_companyName = '#form.application.companyName#'";
stmt = conn.prepareStatement(sql);
ResultSet rs = stmt.executeQuery(sql);
rs.next();
boolean exists;
if( exists = rs.getInt("COUNT(*)") > 0)
{
System.out.println("exists");
}
else
{
System.out.println("not exists");
}
}
}
catch (Exception e)
{
System.err.println("Exception: " + e.getMessage());
}
finally
{
try {
if(conn != null)
{
conn.close();
}
}
catch(SQLException e)
{
}
}
BR
1 Comment
Pete
Not sure what your question is. Are you trying to populate a form? Or are you trying to set form field values?
If you're trying to populate a form field try these links:
[Prepopulate form fields|]
Prepopulate form select list
If you're trying to set form field values from within a Beanshell Tool (within the workflow), take a look at this discussion http://dev.joget.org/community/pages/viewpage.action?pageId=8717213&focusedCommentId=8717244#comment-8717244
This code snippet shows an example how how to update one form field from a Beanshell tool.
import org.joget.apps.app.service.AppService; import org.joget.plugin.base.PluginManager; import org.joget.workflow.model.service.WorkflowManager; import org.joget.form.model.service.FormManager; import org.joget.form.model.Form; import org.joget.apps.app.service.AppUtil; import org.springframework.context.ApplicationContext; import org.joget.apps.form.model.*; ApplicationContext ac = AppUtil.getApplicationContext(); AppService appService = (AppService) ac.getBean("appService"); String primaryKeyValue="#assignment.processId#"; //Load the row using the appId, version, form ID and primaryKey value (process ID) FormRowSet rowSet = appService.loadFormData("myApp","1","myForm",primaryKeyValue); //Get the row data FormRow row = rowSet.remove(0); //Update the field you want to update with the value row.setProperty("customerFirstname","Some fake name"); //Add it back in rowSet.add(row); //Update the table appService.storeFormData("myApp","1","myForm",rowSet,primaryKeyValue);