1. Overview
This article shows how to trigger a new Joget workflow process from BeanShell. The script finds a target process definition, reads related records, passes workflow variables, and starts a child process for each matching row.
2. How It Works
- Define the process key to start.
- Resolve the full process definition ID for the current app version.
- Read the parent record ID and creator.
- Query child records related to the parent request.
- Build a variables map for each child process.
- Start the process with workflowManager.processStart(...).
3. Where to Use in Joget
- Workflow Builder: Tool activity after a parent request is submitted.
- Form Builder: post-processing script for parent-child workflow creation.
- Scheduler Plugin: batch process creation from pending records.
4. Full Code
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 = "child_process_key";
//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 planId = "#form.parent_request.id#";
String createdBy = "#form.parent_request.createdBy#";
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_child_records WHERE c_parent_id = ?");
stmt.setObject(1, planId);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
LogUtil.info(appDef.toString(), "Processing parent request " + planId + " - Record: " + rs.getObject("id"));
Map variables = new HashMap();
variables.put("assignedTeam", rs.getObject("c_assigned_team"));
variables.put("targetPeriod", rs.getObject("c_target_date"));
LogUtil.info("Visit Monthhhhhh from 1st Process", rs.getObject("c_target_date"));
WorkflowProcessResult result = workflowManager.processStart(processDefId, null, variables, createdBy, rs.getObject("id"), false);
LogUtil.info(appDef.toString(), "Processing parent request " + planId + " - Record: " + rs.getObject("id") + " - Status: " + result.getProcess().getInstanceId());
}
}
} catch(Exception e) {
LogUtil.error(appDef.toString(), e, "Error in creating parent request " + planId);
} finally {
//always close the connection after used
try {
if(con != null) {
con.close();
}
} catch(SQLException e) {/* ignored */}
}
5. Example Use Cases
- Starting one child workflow per selected item.
- Creating follow-up inspection or review processes.
- Triggering approval workflows from a parent planning record.
- Splitting one request into multiple workflow instances.
6. Customization Tips
- Replace child_process_key with your process key.
- Replace child table and field names with your app's generic fields.
- Pass only the variables required by the child process.
- Log both parent ID and new child instance ID for support tracing.
7. Key Benefits
- Automates child workflow creation.
- Keeps parent and child records linked.
- Supports batch process creation.
- Uses Joget's built-in workflow APIs.
8. Security Note
Validate that the current user or workflow state is allowed to trigger child processes. Avoid exposing internal process keys and table names in public articles.
9. Final Thoughts
This is a practical pattern for parent-child workflows in Joget. Start with one child record in testing, confirm the variables are received correctly, and then enable batch creation.







