1
0
-1

Using version 8.1.6 community. Implemented a bean for a route. The following two lines of code:

LogUtil.info("Value of activityId               : ", "#assignment.activityId#");
LogUtil.info("Value of workflowAssignment       : ", workflowAssignment.toString());

give the following result, which is unexpected:

INFO 28 Oct 2024 12:25:59 Value of activityId : - #assignment.activityId#
2193
ERROR 28 Oct 2024 12:25:59 org.joget.apps.app.service.AppPluginUtil - Error executing script, line number: 34
2194
bsh.EvalError: Sourced file: inline evaluation of: ``import org.joget.workflow.model.DecisionResult; import org.joget.commons.util.Lo . . . '' : Attempt to resolve method: toString() on undefined variable or class name: workflowAssignment


    CommentAdd your comment...

    3 answers

    1.  
      2
      1
      0

      The error specifically indicates that undefined variable or class name: workflowAssignment This could mean it wasn't initialized properly. Try the below code to verify the same. 

      if (workflowAssignment != null) {
          LogUtil.info("Value of workflowAssignment : ", workflowAssignment.toString());
      } else {
          LogUtil.info("workflowAssignment is null","");
      }


      Additionally check if you have imported the necessary package

      import org.joget.workflow.model.WorkflowAssignment;


      Let us know if this works. Please share your full beanshell script if possible for further debugging. 


        CommentAdd your comment...
      1.  
        1
        0
        -1

        and here now the two scripts:


        This is working:

        Route A has a transition to Tool B.

        Bean in Route A

        import org.joget.workflow.model.DecisionResult;
        import org.joget.commons.util.LogUtil;
        import org.joget.workflow.model.service.*;


        String groupsRequested = "#form.account_signup.groupsRequested#";
        int groupsRequestedArraySize;
        String[] groupsRequestedArray = groupsRequested.split(";");

        if (groupsRequested != "") {
            groupsRequestedArraySize = groupsRequestedArray.length;
        } else {
            groupsRequestedArraySize = 0;
        }

        int groupCounter = Integer.valueOf("#variable.groupCounter#");


        //LogUtil.info("Value of groupCounter             : ", "" + groupCounter);
        //LogUtil.info("Value of groupsRequested          : ", groupsRequested);
        //LogUtil.info("Value of groupsRequestedArray     : ", Arrays.toString(groupsRequestedArray));
        //LogUtil.info("Value of groupsRequestedArraySize : ", "" + groupsRequestedArraySize);


        DecisionResult result = new DecisionResult();
         
        if (groupCounter >= groupsRequestedArraySize ) {
            result.addTransition("noGroupUpdate");
        //    LogUtil.info("Value of Transition             : ", "noGroupUpdate");
            
        } else {
            result.addTransition("groupUpdate");
        //    LogUtil.info("Value of Transition             : ", "groupUpdate");
        }
         
        result.setIsAndSplit(true);
         
        return result;

        Bean in Tool B


        import org.joget.commons.util.LogUtil;
        import org.joget.workflow.model.service.*;


        String groupsRequested = "#form.account_signup.groupsRequested#";

        String[] groupsRequestedArray = groupsRequested.split(";");

        int groupCounter = Integer.valueOf("#variable.groupCounter#");

        //LogUtil.info("Value of groupCounter             : ", "" + groupCounter);
        //LogUtil.info("Value of groupsRequestedArray     : ", Arrays.toString(groupsRequestedArray));
        //LogUtil.info("Value of workflowAssignment       : ", workflowAssignment.toString());

        String group = groupsRequestedArray[groupCounter++];

        WorkflowManager wm = (WorkflowManager) pluginManager.getBean("workflowManager");
        wm.activityVariable(workflowAssignment.getActivityId(),"group", group);
        wm.activityVariable(workflowAssignment.getActivityId(),"groupCounter", String.valueOf(groupCounter));

        //LogUtil.info("Value of groupCounter             : ", "" + groupCounter);
        //LogUtil.info("Value of group                    : ", "" + group);


        This is not working:

        All code is in the Bean for Route A, not Tool B.


        import org.joget.workflow.model.DecisionResult;
        import org.joget.commons.util.LogUtil;
        import org.joget.workflow.model.service.*;


        String groupsRequested = "#form.account_signup.groupsRequested#";
        int groupsRequestedArraySize;

        int groupCounter = Integer.valueOf("#variable.groupCounter#");

        String[] groupsRequestedArray = groupsRequested.split(";");

        String group = groupsRequestedArray[groupCounter++];

        WorkflowManager wm = (WorkflowManager) pluginManager.getBean("workflowManager");


        wm.activityVariable(workflowAssignment.getActivityId(),"group", group);

        // This line above throws already error since workflowAssignment is null


        wm.activityVariable(workflowAssignment.getActivityId(),"groupCounter", String.valueOf(groupCounter));


        if (groupsRequested != "") {
            groupsRequestedArraySize = groupsRequestedArray.length;
        } else {
            groupsRequestedArraySize = 0;
        }

        int groupCounter = Integer.valueOf("#variable.groupCounter#");


        //LogUtil.info("Value of groupCounter             : ", "" + groupCounter);
        //LogUtil.info("Value of groupsRequested          : ", groupsRequested);
        //LogUtil.info("Value of groupsRequestedArray     : ", Arrays.toString(groupsRequestedArray));
        //LogUtil.info("Value of groupsRequestedArraySize : ", "" + groupsRequestedArraySize);


        DecisionResult result = new DecisionResult();
         
        if (groupCounter >= groupsRequestedArraySize ) {
            result.addTransition("noGroupUpdate");
        //    LogUtil.info("Value of Transition             : ", "noGroupUpdate");
            
        } else {
            result.addTransition("groupUpdate");
        //    LogUtil.info("Value of Transition             : ", "groupUpdate");
        }
         
        result.setIsAndSplit(true);
         
        return result;

          CommentAdd your comment...
        1.  
          1
          0
          -1

          I checked the same code in a tool and not inside a route bean. It works there. So it seems, that workflowassignment is not propagated to the route bean but only to a tool bean.

          I cannot think of any reason why this should be a feature and not a bug.

          Anyway by splitting the code into a tool and a route it is possible to work around it.

            CommentAdd your comment...