1
0
-1

Hello,

In a process, I need to call a same subflow several times in parallel.

With the subflow item in process designer, I have two problems :

  • all the subprocess share the same demand (I need differents demands)
  • the task is not visible for the user. The demand is not create.

So I created the script below in a tool of principal process.

I works but what is the best way ? 

Can I use subflow item ?


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;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.joget.commons.util.UuidGenerator;
  
public Object execute(WorkflowAssignment assignment, AppDefinition appDef, HttpServletRequest request) {
    AppService appService = (AppService) AppUtil.getApplicationContext().getBean("appService");
    WorkflowManager workflowManager = (WorkflowManager) AppUtil.getApplicationContext().getBean("workflowManager");
     
    // **************************************** 
    // Variables à modifier
    // **************************************** 
    String type_demande = "mobilier" ;
    // **************************************** 
    
    //get current record id
    String recordId = appService.getOriginProcessId(assignment.getProcessId());

    //get process
    WorkflowProcess process = appService.getWorkflowProcessForApp(appDef.getAppId(), appDef.getVersion().toString(), "demande_traitement");
     
    Connection con = null;
     
    try {
        //Get Joget's current datasource configs
        DataSource ds = (DataSource) AppUtil.getApplicationContext().getBean("setupDataSource");
 
        con = ds.getConnection();
         
        if(!con.isClosed()) {
            //To generate new record IDs for storing into child table
            UuidGenerator uuid = UuidGenerator.getInstance();
             
            String pId = uuid.getUuid();

                 
            String insertSql = "INSERT INTO app_fd_mvt_dmd (id,dateCreated, c_idAgent,c_type_demande) VALUES (?,DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s'),?,?);";
                 
            PreparedStatement stmtInsert = con.prepareStatement(insertSql);
                 
            stmtInsert.setString(1, pId);
            stmtInsert.setString(2, recordId);
            stmtInsert.setString(3, type_demande);

            //Execute SQL statement
            stmtInsert.executeUpdate();
            
            Map variables = new HashMap();
            variables.put("type_demande", type_demande);
            variables.put("N1", "#variable.N1#");
            variables.put("idAgent", recordId);
            
            //start process
            workflowManager.processStart(process.getId(), null, variables,"admin", pId, false);
            
            
        }
    } catch (Exception ex) {
        LogUtil.error("Mouvement des agents", ex, "Erreur lancement processus");
    } finally {
        try {
            if (con != null) {
                con.close();
            }
        } catch (Exception ex) {
            LogUtil.error("Mouvement des agents", ex, "Error closing the jdbc connection");
        }
    }
 
    return null;
}
  
//call execute method with injected variable
return execute(workflowAssignment, appDef, request);
  1. Chris Angel

    Hello there, I know it may be off topic, but I noticed that your bean shell script above did not import the org.joget.commons.util.LogUtil class. Just noting because you are calling those methods in your catch blocks.

    See LogUtil

  2. Didier Testelin

    Thank you for this correction.

CommentAdd your comment...

1 answer

  1.  
    1
    0
    -1

    Hi, I don't see any problem with this method if it works. Using a subflow should work too, did you map the participants correctly? There is a sample app at Sample Application with Subflow.

      CommentAdd your comment...