Versions Compared

Key

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

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:

...

This beanshell script retrieves workflow variable 'ApprovalLevel', converts it to an integer, adds 1, and stores it back as the same workflow variable.