Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The Bean Shell plugin allows one to write custom Java code to achieve what other process tools may not.

Image Added

Figure 1: Bean Shell Properties

NameDescription
ScriptScript in Java. Please see Bean Shell Programming Guide for code example. 

 

Activity Tool Type Plugin

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 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 :

  • pluginManager
  • workflowAssignment
  • appDef  - AppDefinition

A Beanshell activity tool type plugin that sets a form data:

 

import java.util.HashMap;
import java.util.Map;
import org.joget.apps.app.model.AppDefinition;
import org.joget.apps.app.service.AppService;
import org.joget.apps.app.service.AppUtil;
import org.joget.apps.form.model.FormRow;
import org.joget.apps.form.model.FormRowSet;
import org.joget.apps.form.service.FormUtil;
import org.joget.workflow.model.WorkflowAssignment;
import org.joget.workflow.util.WorkflowUtil;
 
//Constant variable
String formDefId = "approvalForm";
 
//Service bean
AppService appService = (AppService) AppUtil.getApplicationContext().getBean("appService");
 
//Get primary key
String id = appService.getOriginProcessId(workflowAssignment.getProcessId());
 
//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);

 

Increment a workflow variable value:

 

import org.joget.workflow.model.service.WorkflowManager;
 
WorkflowManager workflowManager = (WorkflowManager) pluginManager.getBean("workflowManager");
String approvalLvl = workflowManager.getProcessVariable(workflowAssignment.getProcessId(), "ApprovalLevel");
String newApprovalLvl = String.valueOf(Integer.parseInt(approvalLvl)+1);
workflowManager.activityVariable(workflowAssignment.getActivityId(), "ApprovalLevel", newApprovalLvl);

 

...