Joget DX 8 Stable Released
The stable release for Joget DX 8 is now available, with a focus on UX and Governance.
...
Code Block | ||
---|---|---|
| ||
SELECT * FROM app_fd_gda_travel WHERE c_batch = '#form.gda_batch.id#' |
In the batch form itself, we can make use of "Post Form Submission Processing" to capture event of "Data Creation" or "Both data creation and update", whichever suits your own use case, to execute bean shell Java code to achieve this.
aa
Code Block | ||||
---|---|---|---|---|
| ||||
import org.joget.workflow.model.service.WorkflowManager;
import org.joget.apps.app.service.AppUtil;
import org.joget.apps.app.service.AppService;
import org.joget.workflow.model.WorkflowAssignment;
import org.joget.workflow.util.WorkflowUtil;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.joget.workflow.model.WorkflowProcess;
import org.joget.workflow.model.WorkflowProcessResult;
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;
//define process to start
String processDefKey = "travel_approver_process";
//utility bean
WorkflowManager workflowManager = (WorkflowManager) AppUtil.getApplicationContext().getBean("workflowManager");
AppService appService = (AppService) AppUtil.getApplicationContext().getBean("appService");
//get processDefId
WorkflowProcess processDef = appService.getWorkflowProcessForApp(appDef.getId(), appDef.getVersion().toString(), processDefKey);
String processDefId = processDef.getId();
//get foreign key
String batchId = "#form.gda_batch.id#";
Connection con = null;
try {
// retrieve connection from the default datasource
DataSource ds = (DataSource)AppUtil.getApplicationContext().getBean("setupDataSource");
con = ds.getConnection();
// execute SQL query
if(!con.isClosed()) {
PreparedStatement stmt = con.prepareStatement("SELECT * FROM app_fd_gda_travel WHERE c_batch = ?");
stmt.setObject(1, batchId);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
LogUtil.info(appDef.toString(), "Processing Batch " + batchId + " - Record: " + rs.getObject("id"));
Map variables = new HashMap();
//variables.put("batch", batchId);
WorkflowProcessResult result = workflowManager.processStart(processDefId, null, variables, "admin", rs.getObject("id"), false);
LogUtil.info(appDef.toString(), "Processing Batch " + batchId + " - Record: " + rs.getObject("id") + " - Status: " + result.getProcess().getInstanceId());
}
}
} catch(Exception e) {
LogUtil.error(appDef.toString(), e, "Error in creating approval process for batch " + batchId);
} finally {
//always close the connection after used
try {
if(con != null) {
con.close();
}
} catch(SQLException e) {/* ignored */}
}
|
aa