cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic assignment using a process variable

birgir
Champ in-the-making
Champ in-the-making
Hi

I am having problems with a simple script where I need to store the previous user inorder to assign them the task again if reviewer rejects the work.

I store the username in art_author.

<task-node name="ArtistPool">
   <task name="piwf:artistPool" swimlane="artistPool" />
      
   <transition to="Reader_1" name="Accept">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
         <script>
            <expression>            
            art_author =  person.properties.userName;
                  
            logger.log("art_author:" + art_author);
            </expression>
            <variable name="art_author" access="write" />
         </script>
      </action>
         
   </transition>
   
</task-node>

In another node I want to assign a task using art_author.


<task-node name="Artist">
      <task name="piwf:artist">
      <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
         <actor>#{people.getPerson(art_author)}</actor>
      </assignment>
      </task>
      
      <transition to="Reader_1" name="Accept"></transition>

   </task-node>

I get a nullpointer exception when running this.

Caused by: org.jbpm.graph.def.DelegationException: actor expression '#{people.getPerson(art_author)}' evaluates to null

Havent seen examples where one needs to read in the process variable when using the reference #{}. What am I doing wrong here.
10 REPLIES 10

bedag-moo
Champ in-the-making
Champ in-the-making
to assign them the task again if reviewer rejects the work.

This is usually done with jBPM swimlanes. For instance:


   <swimlane name="editor">
      <assignment   class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
         <actor>#{bpm_assignee}</actor>
      </assignment>
   </swimlane>
   
   <task-node name="edit">
      <task name="your:taskmodel" swimlane="editor"/>
      <transition name="Done" to="review"/>
   </task-node>

A brief explanation: The first time the swimlane is used, a user is assigned to that swimlane with the specified assignment handler. Whenever a task is assigned the swimlane (the first time or later), the user assigned to the swimlane gets the task.

birgir
Champ in-the-making
Champ in-the-making
Thanks,

I am using a pool of actors and each one of them could take the task on and submit to review. This is why I need to record which one it was so in case of reject only he would be assigned to the revision.

I am therefore not using the bpm_assignee aspect directly, is it updated whenever a person takes ownership of a task ?

Seems that art_author is not collected properly in the second node. If I hard code a username in people.getPerson("some_username") it works fine.

Here is my complete process def.


<?xml version="1.0" encoding="UTF-8"?>

<process-definition  xmlns="urn:jbpm.org:jpdl-3.1"  name="Pindar Set Process">
<swimlane name="initiator" />

<!–  Define swimlanes for the three roles –>

   <swimlane name="artistPool">
      <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
         <pooledactors>#{people.getGroup('GROUP_artists')}</pooledactors>
      </assignment>
   </swimlane>
   
   <swimlane name="readers_1">      
      <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
         <pooledactors>#{people.getGroup('GROUP_readers_1')}</pooledactors>
      </assignment>
   </swimlane>
   
   <swimlane name="readers_2">
      <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">         
         <pooledactors>#{people.getGroup('GROUP_readers_2')}</pooledactors>               
      </assignment>
   </swimlane>
   

   <start-state name="start-state1">
      <task name="piwf:submitAd" swimlane="initiator" />
      
      <transition to="ArtistPool">
       <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
         <script>
            logger.log("starting state");
         </script>
      </action>
      
      </transition>
   </start-state>


   <task-node name="ArtistPool">
          <task name="piwf:artistPool" swimlane="artistPool" />
          <!– Lets record which artist sends the work to the reader –>
         
      <transition to="Reader_1" name="Accept">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
         <script>
            <expression>
               art_author =  person.properties.userName;
               logger.log("art_author:" + art_author);
            </expression>
            <variable name="art_author" access="write" />
            </script>
         </action>
         
      </transition>
      
   </task-node>

   <task-node name="Reader_1">
      <task name="piwf:readers_1" swimlane="readers_1" />
      
      <transition to="Reader_2" name="Accept"></transition>
      <transition to="Artist" name="Reject"></transition>
   </task-node>

   <task-node name="Reader_2">
      <task name="piwf:readers_2" swimlane="readers_2" />
      
      <transition to="completed" name="Accept"></transition>
      <transition to="Artist" name="Reject"></transition>
   </task-node>

   <node name="completed">
      <transition to="end-state1"></transition>
   </node>

   <task-node name="Artist">
      <task name="piwf:artist">
      <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
         <actor>#{people.getPerson(art_author)}</actor>
      </assignment>
      </task>
      
      <transition to="Reader_1" name="Accept"></transition>

   </task-node>


   <end-state name="end-state1"></end-state>

      
</process-definition>

bedag-moo
Champ in-the-making
Champ in-the-making
I am using a pool of actors and each one of them could take the task on and submit to review. This is why I need to record which one it was so in case of reject only he would be assigned to the revision.

I see. I don't know how to do that with swimlanes either.

is it updated whenever a person takes ownership of a task ?

bpm:assignee is not (AFAIK). Ownership is recorded, but I doubt that this information is exposed to scripts. ==> Manually recording the submitting artist looks like the best option to me, too. Alas, I don't know why your code doesn't work. What does the logger say?

birgir
Champ in-the-making
Champ in-the-making
It seems that my process variable 'art_author' is not defined when I use it in the second node.

However, doing the same procedure using a integer process variable works fine. Can it be an issue using custom text process variables ?

The simple example writes the string person.properties.userName into art_author and in the next node the same variable is read. Here is what I got.


16:13:37,687 DEBUG [org.alfresco.repo.jscript.ScriptLogger] inside pool artist1
16:13:45,234 DEBUG [org.alfresco.repo.jscript.ScriptLogger] inside reader undefined


<task-node name="ArtistPool">
          <task name="piwf:artistPool" swimlane="artistPool" />
                   
      <transition to="Reader_1" name="Accept">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>            
               <variable name="art_author" access="write" />
               <expression>            
                  art_author = person.properties.userName;
                  logger.log("inside pool " + art_author);
               </expression>
            </script>
         </action>
      </transition>
      
   </task-node>
         
   <task-node name="Reader_1">
      <task name="piwf:readers_1" swimlane="readers_1" />
      
      <transition to="Reader_2" name="Accept">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>      
               <variable name="art_author" access="read" />
               <expression>         
                  logger.log("inside reader " + art_author);
               </expression>      
            </script>
         </action>
      </transition>
      
      <transition to="Artist" name="Reject"></transition>
   </task-node>

birgir
Champ in-the-making
Champ in-the-making
I found a simple workaround for those having similar problems.

If you want to record a variable with global scope (process variable) you can use the executioncontext from the beanshell interface.


executioncontext.setVariable("name_of_var","value");

The interface provided can be called from Javascript. I did the following.


<transition to="Reader_1" name="Accept">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               art_author = person.properties.userName;
               executionContext.setVariable("art_author",art_author);
            </script>   
         </action>   
      </transition>

bedag-moo
Champ in-the-making
Champ in-the-making
Thanks for sharing that, it just saved me from having to hunt down a solution myself.

poptarts
Champ in-the-making
Champ in-the-making
Thanks for sharing that, it just saved me from having to hunt down a solution myself.

same here. Thanks a bunch!

robain
Champ in-the-making
Champ in-the-making
I have something like this..

  <start-state name="start">
        <task name="matriawf:startContentReviewTask" swimlane="initiator" />
      <transition name="" to="Submit">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>      
               group = 'GROUP_myGroup';
               executionContext.setVariable("group", group);
            </script>
         </action>
      </transition>
   </start-state>
   …..

   <task-node name="Review">
      <task name="matriawf:contentReviewTask" >
         <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
            <pooledactors>#{people.getGroup(group)}</pooledactors>
           </assignment>
        </task>
       <transition name="approve" to="Approve" >

but i still get "group" is not defined error on the javascript debugger.

Any ideas ?

thanks.

mrogers
Star Contributor
Star Contributor
Looks like art_author is not defined.

Have you defined a process model for each of your tasks, in this case one that defines art_author?

When each tasks begins or ends task property values are copied from and to the process.   This is how tasks can communicate with each other. 
You can also take control of the mapping of task to process properties as and when your requirements become complex.