Hi Guys ,

I been trying to change a workflow variable but did not succeed !

Here is my error :

Sourced file: inline evaluation of: ``import org.joget.apps.form.model.*; import org.joget.apps.form.lib.*; import org . . . '' : Typed variable declaration : Attempt to resolve method: getBean() on undefined variable or class name: pluginManager : at Line: 102 : in file: inline evaluation of: ``import org.joget.apps.form.model.*; import org.joget.apps.form.lib.*; import org . . . '' : pluginManager .getBean ( "workflowManager" ) 

Here is my code :

import org.joget.apps.form.model.*;
import org.joget.apps.form.lib.*;
import org.joget.apps.form.service.*;
import java.sql.*;
import org.apache.commons.collections.SequencedHashMap;
import java.util.*;
import org.joget.commons.util.UuidGenerator;
import org.joget.apps.app.service.*;
import org.joget.apps.app.model.*;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.joget.workflow.model.service.*;
import org.joget.workflow.model.*;


public FormRowSet getGridRows() {
	return rows ; // this will return the grid rows
}

public saveGridRows(FormRowSet rows)

{
	Class.forName("com.mysql.jdbc.Driver").newInstance();
	con = DriverManager.getConnection("jdbc:mysql://localhost:3307/jwdb?characterEncoding=UTF-8", "root", "");
	if(!con.isClosed()){

		String recordId = "#requestParam.id#";

		// If you need to query data from different table(s) and process it before saving it to database, you can do it here

		  StringBuffer NewUserList = new StringBuffer();


		UuidGenerator uuid = UuidGenerator.getInstance();

		Iterator i= rows.iterator(); // Iterating grid rows
		while (i.hasNext()) {
			FormRow row = (FormRow) i.next();

			// row.get("GridLabelHere");
			String gridColumn1 = row.get("Userfirstname"); // reading grid column value
			String gridColumn2 = row.get("Userlastname");
			String gridColumn3 = row.get("Useremail");
			String pId = uuid.getUuid(); // generating Primary Key

			//Append users to variable
			NewUserList.append(gridColumn1).append("&");

			// here verify if user exist in database or not
			// manually handle insert and update by checking the data is exist or not

			String FirstName  = gridColumn1 ;
			String LastName = gridColumn2 ;
			String dir_user_mail = gridColumn3 ;
				String[] tokens = dir_user_mail.split("@");
				String userId = tokens[0];

            String selectQuery = "SELECT username FROM dir_user WHERE username=?";
            PreparedStatement stmt = con.prepareStatement(selectQuery);
            stmt.setString(1, userId );
            ResultSet rs = stmt.executeQuery();

            Boolean isExist = false;
            if (rs.next()) {
                isExist = true;
            }

			if (isExist) { // Here the user is being updated !

            } else {       // Here the user is being created !

				String insertQuery = "INSERT INTO dir_user (id, username, firstName, lastName, password, email,active,timezone) values (?, ?, ?, ?,'password', ?,'1','0')";
                PreparedStatement istmt = con.prepareStatement(insertQuery);
                istmt.setString(1, userId);
                istmt.setString(2, userId);
                istmt.setString(3, FirstName);
                istmt.setString(4, LastName);
                istmt.setString(5, dir_user_mail);
                istmt.executeUpdate();

				//Setting role for this new user
    			String SqlSetRole = "INSERT INTO dir_user_role (roleId,userId) " + "values ('ROLE_USER','"+userId+"') ";
    			PreparedStatement statementAffectRole = con.prepareStatement(SqlSetRole);
    			statementAffectRole.executeUpdate();

            }

		////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


		}
	} else


	{
		System.out.println("Connection Problem");
	}

	// ADD TO WORKFLOW VARIABLE
    // String NewUserListFinalV = NewUserList.toString();
	WorkflowManager wm = (WorkflowManager) pluginManager.getBean("workflowManager");
    wm.activityVariable(workflowAssignment.getActivityId(), "user_list", "hello");

	con.close();
}

FormRowSet rows = getGridRows(); // getting the grid rows
saveGridRows(rows); // processing & storing the grid rows

This code , will verify each user that have been entered into a grid . If user doest not exist and account will be created for him/her . All users will be appended to a string variable (user_list) , this string variable will be used to assign a task to the group of users for validation .

I just cant assign a value to a workflow variable . I have created a variable named 'user_list' in my process workflow design .

Your comments and help are the most welcome .

  • No labels

3 Comments

  1. I assume you are executing this piece of code in Bean Shell Form Store Binder.

    Therefore, pluginManager is not available. See "store" method in BeanShellFormBinder.java

    Use the following instead.

    import org.joget.workflow.model.service.WorkflowManager;
    import org.joget.apps.app.service.AppUtil;
    import org.springframework.context.ApplicationContext;
    
    ApplicationContext ac = AppUtil.getApplicationContext();
    WorkflowManager wm = (WorkflowManager) ac.getBean("workflowManager");
    wm.activityVariable("#assignment.activityId#", "variableName", "variableValue");
    1. Thank Walter , it work GREAT ! This was the answer i was looking for . Best , Meven !

  2. excellent answer, also works fine in my case