Versions Compared

Key

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

...

Code Block
languagejava
import java.util.Map;
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;
 
public Object execute(WorkflowAssignment assignment, AppDefinition appDef, HttpServletRequest request) {
    AppService appService = (AppService) AppUtil.getApplicationContext().getBean("appService");
    WorkflowManager workflowManager = (WorkflowManager) AppUtil.getApplicationContext().getBean("workflowManager");
    
    //get current record id
    String recordId = appService.getOriginProcessId(assignment.getProcessId());
    
    //get process
    WorkflowProcess process = appService.getWorkflowProcessForApp(appDef.getAppId(), appDef.getVersion().toString(), "process2");
    
    //start process
    workflowManager.processStart(process.getId(), null, null, null, recordId, false);
    
    return null;
}
 
//call execute method with injected variable
return execute(workflowAssignment, appDef, request);

Update Form Field Value

Code Block
languagejava
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.workflow.model.WorkflowAssignment;

String formDefId = "hr_expense_new";
String fieldId = "status";
String fieldValue = "Submitted";

//Get record Id from process
AppService appService = (AppService) AppUtil.getApplicationContext().getBean("appService");
String id = appService.getOriginProcessId(workflowAssignment.getProcessId());

//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);

 

Use as Userview Permission

...