1
0
-1

Hi Experts,

In the form I have Select box with 3 different options (Created, Inprogress, Closed) - it's variable workflow "status". .

I'm using Post Processing Tool option after create/update form to run "process1" based on Bean Shell

Programming Guide#UseasProcessTool. - below piece of code.

Unfortunately variable workflow "status" from the form is not visible and is not taken into consideration in the process, which causing process end already at the route point.

  • How can I modify existing java code to take as variable field from test_send_email.status ?
  • Any other option to make it? I don't want to add form to the below process - as this is only example and will be used for different purposes.
    The goal is to call a new process after form creation/update which will be sending email based on variable from that form.

 

APP_test_email-1-20160324232122.jwa

 

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(), "process1");
     
    //start process
    workflowManager.processStart(process.getId(), nullnullnull, recordId, false);
     
    return null;
}
  
//call execute method with injected variable
return execute(workflowAssignment, appDef, request);

 

 

 

    CommentAdd your comment...

    2 answers

    1.  
      2
      1
      0

      the WorkflowManager.processStart method allowed u to set workflow variable.

       

      import java.util.Map;
      import java.util.HashMap;
      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(), "process1");
          
          //set variable
          Map variables = new HashMap();
          variables.put("status", "created");
       
          //start process
          workflowManager.processStart(process.getId(), null, variables, null, recordId, false);
           
          return null;
      }
        
      //call execute method with injected variable
      return execute(workflowAssignment, appDef, request);
        CommentAdd your comment...
      1.  
        1
        0
        -1

        Hi O.o,

        thanks for feedback.

        It works, I have modified the code to take status based on select box selection instead to have fixed value "Created".

          new: variables.put("status","#form.test_send_email.status?java#");

           old: variables.put("status", "created");

        So the effect is as shown below.

         


        Thanks,

        Sylwester

          CommentAdd your comment...