cancel
Showing results for 
Search instead for 
Did you mean: 

Activiti Workflow

smcardle
Champ in-the-making
Champ in-the-making
Hi All

I am trying to build a complex automated workflow (no user interaction required) designed using the BPMN 2.0 task types supported by Activiti in the Eclipse Designer, but I have several issues that I can't seem to get over.

1. It seems that if I create a workflow without a userTask, Alfresco throws an NPE.
This is annoying but to get over this I have added a userTask as the first task in my workflow and added an activiti:executionListener "start" event handler with  class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener".
This executionListener just logs the available process variables injected by Alfresco and the output generated is exactly as I expect. But this leads me to problem 2.

2. The number of BPMN task types implemented by Alfresco is VERY limited. To implement my processes I need to use the supported activiti task types, but the Alfresco process variables do not seem to be available to these tasks ???
To try and get over this, I have tried to allocate some of the variables available in the Alfresco userTask (see point 1) to process scoped variables (as in the Activiti way) that would then be available to the rest of the Activiti tasks in the process i.e. in the Alfresco userTask start executionListener I have added this in the script element ….


              var pdfFile = bpm_package.children[0];
              logger.log("pdfFile:" + pdfFile.name);

              execution.setVariable("pdfFile", pdfFile);


However, when the process runs I get the following exception ….


SEVERE: Error while closing command context
org.alfresco.scripts.ScriptException: 05050229 Failed to execute supplied script: Passed value is not an instance of ActivitiScriptNode, cannot set variable value.
   at org.alfresco.repo.jscript.RhinoScriptProcessor.executeString(RhinoScriptProcessor.java:278)
   at org.alfresco.repo.processor.ScriptServiceImpl.executeString(ScriptServiceImpl.java:286)
   at org.alfresco.repo.processor.ScriptServiceImpl.executeScriptString(ScriptServiceImpl.java:193)
   at org.alfresco.repo.processor.ScriptServiceImpl.executeScriptString(ScriptServiceImpl.java:183)
   at sun.reflect.GeneratedMethodAccessor584.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:601)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
<more left out> ….
Caused by: org.activiti.engine.ActivitiException: Passed value is not an instance of ActivitiScriptNode, cannot set variable value.
   at org.alfresco.repo.workflow.activiti.variable.ScriptNodeVariableType.setValue(ScriptNodeVariableType.java:76)
   at org.activiti.engine.impl.persistence.entity.VariableInstanceEntity.setValue(VariableInstanceEntity.java:164)
   at org.activiti.engine.impl.persistence.entity.VariableInstanceEntity.create(VariableInstanceEntity.java:72)
   at org.activiti.engine.impl.persistence.entity.VariableInstanceEntity.createAndInsert(VariableInstanceEntity.java:58)
   at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.createVariableLocal(VariableScopeImpl.java:225)
   at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.setVariable(VariableScopeImpl.java:175)


Can anybody tell me how to convert the Alfresco javascrip objects like the "logger" and Alfresco Document nodes, such as my pdfFile node (shown in the script snippet above) so they are accessable to an Activiti "scriptTask" or "serviceTask" later on in the process ???


Here is my userTask in the bpmn file…


    <userTask id="task1" name="Log workflow variables and properties">
      <extensionElements>
        <activiti:executionListener event="start" class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener">
          <activiti:field name="script">
            <activiti:string>

              var pdfFile = bpm_package.children[0];
              logger.log("pdfFile:" + pdfFile.name);

              // This causes the exception (shown above) so is comment out for the moment.
              // execution.setVariable("pdfFile", pdfFile);

              var reportCode = pdfFile.properties["cps:reportCode"];
              logger.log("reportCode:" + reportCode);

              var businessDate = pdfFile.properties["cps:businessDate"];
              logger.log("businessDate:" + businessDate);

              var productionDate = pdfFile.properties["cps:productionDate"];
              logger.log("productionDate:" + productionDate);

              var expiryDate = pdfFile.properties["cps:expiryDate"];
              logger.log("expiryDate:" + expiryDate);

              var generatedDateTime = pdfFile.properties["cps:generatedDateTime"];
              logger.log("generatedDateTime:" + generatedDateTime);

              var props = pdfFile.properties["cps:props"];
              logger.log("props:" + props);
 
              logger.log("bpm_workflowDescription:" + bpm_workflowDescription);
              logger.log("bpm_workflowDueDate:" +bpm_workflowDueDate);
              logger.log("bpm_workflowPriority:" +bpm_workflowPriority);
              logger.log("bpm_package:" + bpm_package);
              logger.log("bpm_package.children[0]:" + bpm_package.children[0]);
              logger.log("bpm_context:" + bpm_context);
              logger.log("initiator:" + initiator);
              logger.log("initiatorhome:" + initiatorhome);
              logger.log("companyhome:" + companyhome);</activiti:string>
             
          </activiti:field>
        </activiti:executionListener>
      </extensionElements>
    </userTask>



This works fine, I get all the correct values logged to the catalina.out file …

But, I would now like to access the pdfFile variable (and others) in the next task which is an activiti "scriptTask"


    <scriptTask id="scripttask1" name="Get rules for reportCode" scriptFormat="javascript" activiti:autoStoreVariables="false">
      <script>
          var pdfFile = execution.getVariable("pdfFile");
         System.out.println("can I get the pdfFile variable? = " + pdfFile);
      </script>
    </scriptTask>




As I said, I don't want to use the Alfresco task's because the BPMN diagram is then filled with only userTask's and serviceTask's (used by Alfresco to represent a scriptTask ???)


Regards

Steve
1 REPLY 1

smcardle
Champ in-the-making
Champ in-the-making
Does nobody know how to do this ?