import javax.servlet.http.HttpServletRequest;
import org.joget.apps.app.model.AppDefinition;
import org.joget.apps.app.service.AppService;
import org.joget.apps.app.service.AppUtil;
import org.joget.workflow.model.service.WorkflowManager;
import org.joget.workflow.model.WorkflowAssignment;
import org.joget.workflow.model.WorkflowProcess;
import org.joget.apps.form.model.FormRow;
import org.joget.apps.form.model.FormRowSet;
 
public void execute(WorkflowAssignment assignment, AppDefinition appDef, HttpServletRequest request) {
	String formDefId = "bs_tool_update_form"; //app id
	String fieldId = "test";  //更改的字段名
	String fieldValue = "close";    //更改的字段值
		 
	//Get record Id from process
	AppService appService = (AppService) AppUtil.getApplicationContext().getBean("appService");
	String id = appService.getOriginProcessId(assignment.getProcessId());  //获取当前流程中的表单数据id
		 
	//retrieve data
	FormRow row = new FormRow();
	FormRowSet rowSet = appService.loadFormData(appDef.getAppId(), appDef.getVersion().toString(), formDefId, id);
	if (!rowSet.isEmpty()) {
		row = rowSet.get(0);
		//update field value
		row.setProperty(fieldId, fieldValue);
	}
		 
    //Store the updated data
	rowSet.set(0, row);
	appService.storeFormData(appDef.getAppId(), appDef.getVersion().toString(), formDefId, rowSet, id);
}
/*
workflowAssignment,pluginManager, appDef, request 为当前beanShell的全局变量,可根据需要使用
    workflowAssignment-工作流工具活动分配对象。(org.joget.workflow.model.WorkflowAssignment)
    pluginManager-插件管理器服务bean,以方便使用。(org.joget.plugin.base.PluginManager)
    appDef-流程的App定义。(org.joget.apps.app.model.AppDefinition)
    request-当前HTTP请求的Http请求对象。如果工具是由截止日期触发的,则不可用。(javax.servlet.http.HttpServletRequest)
*/
//call execute method with injected variable
execute(workflowAssignment, appDef, request);

样例应用

APP_BeanShellTest-1-20200109105727.jwa

  • No labels