cancel
Showing results for 
Search instead for 
Did you mean: 

how to create global process variables

boneill
Star Contributor
Star Contributor
hi All,

I have been pulling my hair out for two days on this so would really appreciate any pointers:

I have a task that sets a variable called signOff to either true or false depending on whether I have collected a value from a user.  I have debugged this and this part works:


<task-node name="validsignoff" >
        <task name="validwf:validSignOffTask" swimlane="initiator">    
        </task>
        <transition name="approve" to="signoffreceived" >
           <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                   <script>               
                      <variable name="validwf_validid" access="read"/>
                      <variable name="signOff" access="write" />
                      <expression>
                          logger.log("Valid ID = " + validwf_validid);
                          signOff = false;
                          if (validwf_validid != null &amp;&amp; validwf_validid.length != 0)
                             signOff = true;
                         
                                                     logger.log("ValidSignOFF - signOff = " + signOff);
                       </expression>
                   </script>
               </action>
        </transition>
       <transition to="rejected" name="reject"></transition>
    </task-node>

I then read this variable value in a decision node to determine which path to follow, onto end if user has entered a value, or back to the originating node if the user has not set a value.

<decision name="signoffreceived">         
      <transition to="validsignoff" name="incompletesignoff">
         <condition>#{signOff == false}</condition>
      </transition>
      <transition to="endreview">
         <condition>#{signOff == true}</condition>
      </transition>
   </decision>

However it does not work as signOff comes up as undefined. 
So how do I set signOff to be a gloabal variable and how do I evaluate it in the transition code.

Any help really, really appreciated. 

Regards
4 REPLIES 4

_sax
Champ in-the-making
Champ in-the-making
To be global, you could try to leave out the line
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
leaving
<transition name="approve" to="signoffreceived" >
       <script>
    …
       </script>
</transition>
And you could try to define that variable in your model definition in the first task-node it occurs in.

I've, too been pulling on this topic, before.

vinaxwater
Champ in-the-making
Champ in-the-making

<decision name="isViewed">
   <event type="node-enter">
        <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
           <script>
               <variable name="wf_reviewerCount" access="read"/>
               <expression>logger.log(wf_reviewCount);</expression>
          </script>
        </action>
        </event>
</decision>
That code for Read parameter wf_reviewerCount  :mrgreen: Options for access is: Read, Write or both Read and Write (e.x: access="read,write")

Regard
vinaxwater

jayjayecl
Confirmed Champ
Confirmed Champ
The easiest way is to push your variable in the executionContext :

executionContext.setVariable("signOff", signOff);

You can do that either in a Java class, or in script… and signOff will then be easily accessible using
var signOff = executionContext.getVariable("signOff");

kbootz
Champ in-the-making
Champ in-the-making
Create an event of type "process-start" and define your variables there, ie.,:

  <event type="process-start">
     <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
        <script>
         <variable name="Thewf_CreatedBy" access="read,write" />
       <expression>
          Thewf_CreatedBy="";
        </expression>
       </script>
      
        <script>
         <variable name="Thewf_CreationDate" access="read,write" />
       <expression>
          Thewf_CreationDate="";
        </expression>
       </script>
     </action>
  </event>