Joget DX 8 Stable Released
The stable release for Joget DX 8 is now available, with a focus on UX and Governance.
...
Set value to a workflow variable:
...
Code Block |
---|
import java.sql.*Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import javax.sql.DataSource; import org.joget.apps.app.service.AppUtil; 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.createStatement(prepareStatement("UPDATE table1 SET column1='value1'"); stmt.executeUpdate("UPDATE formdata_simpleflow set c_status='#assignment.activityId#' WHERE processId='#assignment.processId#'"); } } catch(Exception e) { System.err.println("Exception: " + e.getMessage()); } finally { try { if(con != null) { con.close(); } } catch(SQLException e) { } } |
Anchor | ||||
---|---|---|---|---|
|
A participant type plugin should return a collection of usernames. In the participant plugin, there are two context variables available for the script to use :
...
Code Block |
---|
import java.util.ArrayList; a = new ArrayList(); a.add("jack"); // one username return a; |
Get all users from the DirectoryManager and assigning them:
Code Block |
---|
import java.util.Collection;
import java.util.ArrayList;
import org.joget.apps.app.service.AppUtil;
import org.joget.directory.model.service.ExtDirectoryManager;
import org.joget.directory.model.User;
import org.springframework.context.ApplicationContext;
ApplicationContext ac = AppUtil.getApplicationContext();
ExtDirectoryManager directoryManager = (ExtDirectoryManager) ac.getBean("directoryManager");
Collection results = new ArrayList();
Collection userList = directoryManager.getUserList();
for (User u : userList) {
results.add(u.getUsername());
}
return results; |
Activity Tool Type Plugin is a plugin that will be executed when the workflow reaches a System Tool activity. System Tool activities must be placed in the workflow diagram and then the Beanshell plugin configured in the Process's Activity Mapping for this to work. In this plugin, there are two context variables available for the script to use :
Code Block |
---|
import java.util.ArrayListHashMap; import java.util.logging.Logger.Map; import org.joget.apps.app.model.AppDefinition; import org.joget.pluginapps.app.baseservice.PluginManagerAppService; import java.util.logging.FileHandlerorg.joget.apps.app.service.AppUtil; import org.joget.workflowapps.form.model.service.WorkflowManagerFormRow; import org.joget.apps.form.model.FormRowSet; import org.joget.apps.form.service.FormManagerFormUtil; import org.joget.formworkflow.model.Form; FormManager formManagerWorkflowAssignment; import org.joget.workflow.util.WorkflowUtil; //Constant variable String formDefId = "approvalForm"; //Service bean AppService appService = (FormManagerAppService) pluginManagerAppUtil.getApplicationContext().getBean("formManagerappService"); processId //Get primary key String id = appService.getOriginProcessId(workflowAssignment.getProcessId()); Form form = formManager.loadDynamicFormByProcessId("T01", processId); // in this example, form's table is T01 formData = form.getCustomProperties(); formData.put("c_columnname","new value"); // the form data field to be set is columnname form.setCustomProperties(formData); formManager.saveForm(form //Get existing data FormRowSet rowSet = appService.loadFormData(appDef.getAppId(), appDef.getVersion().toString(), formDefId, id); FormRow row = null; if (rowSet == null || rowSet.isEmpty()) { rowSet = new FormRowSet(); row = new FormRow(); row.setId(id); rowSet.add(row); } else { row = rowSet.get(0); } //Set values row.setProperty("field1", "value 1"); row.setProperty("field2", "value 2"); row.setProperty("field3", "value 3"); //Save appService.storeFormData(appDef.getAppId(), appDef.getVersion().toString(), formDefId, rowSet, id); |
...