cancel
Showing results for 
Search instead for 
Did you mean: 

Global variable accessed by beanshell or/and javascript

matjazmuhic
Champ on-the-rise
Champ on-the-rise
I wanna have a global scoped variable that all tasks can access either inside javascript or beanshell script. I have this code and I get null for requiredApprovePercent variable:

Start task with defined variable: requiredApprovePercent


<start-state name="start">
  <task name="agfo:submitForReviewTask3">
   <event type="task-end">
    <script>
     <variable name="task_comment" access="read,write"/>
     <variable name="task_id" access="read,write"/>
     <variable name="requiredApprovePercent" access="read,write"/>
     <expression>
      if(taskInstance.comments.get(0).message != null) task_comment = taskInstance.comments.get(0).message;
      if(taskInstance.id != null) task_id = taskInstance.id; 
     </expression>
    </script>
   </event>
  </task>
  <event type="node-leave">
   <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
    <script>
     …
     var configNodeRef = bpm_package.children[0].properties["aginv:ChosenConfigNodeRef"];
     var config = search.findNode(configNodeRef);
     requiredApprovePercent = config.properties["agfo:wfRequiredApprovalPercent"];
     …
    </script>
   </action>
  </event>
  <transition to="fork"/>
</start-state>

Decision node where I want to access that variable:


<decision name="reviewDecision">
  <event type="node-enter">
   <script>
    <expression>
     …
     System.out.println("requiredApprovePercent= " + requiredApprovePercent);
     …
    </expression>
   </script>
  </event>
  <transition to="a">
   <condition>#{………….}</condition>
  </transition>
  <transition to="b"/>
</decision>
3 REPLIES 3

mrogers
Star Contributor
Star Contributor
You need to read the JBPM documentation with respect to the mapping between "process variables" and "task variables".

In alfresco we tend to define an aspect that contains all the "global variables", look at the existing workflows for examples.

matjazmuhic
Champ on-the-rise
Champ on-the-rise
I tried also defining the controller and variable mapping but I can't load definition after I add those tags into process definition.

Problem with second approach (aspects) is that I start workflow from javascript. Can I somehow get start-task in javascript and set the aspect property there?

cfox
Champ in-the-making
Champ in-the-making
MRogers,
Can you elaborate on aspects and "Global Variables".   My understanding of global variables is that there is one copy of the value that can be accessed at any scope.   An aspect is a definition that is applied to a type.  When applied each type gets its own copy so an aspect is NOT global. 

I looked at workflowmodel.xml which has the aspect applied to two different types.  Can you provide a code example of how to create and acess global variables?