cancel
Showing results for 
Search instead for 
Did you mean: 

Advanced Workflow : task-assign + Task Done

timothy_michael
Champ in-the-making
Champ in-the-making
I'm finding two pieces of strange behavior with scripts in my advanced Workflow.

I'm trying to send e-mails to users when they are assigned a task using the task-assign event. That's working fine. But when the user clicks "Task Done" on the task to continue it on that workflow path, I'm finding task-assign is getting fired again, and the user is getting another e-mail before it moves to the next task.  This is obviously not desirable.

So, to work around it, I started by putting taskInstance.previousActorId and taskInstance.actorId in the body of the e-mail to see their values. The first time into the task, it's null and "author", respectively. The e-mail that gets sent when I click "Task Done", they're both set to "author".

I figured a taskInstance.previousActorId!=taskInstance.actorId conditional surrounding my script would fix the problem, but it seems in both cases that conditional is returning true. I'm pretty perplexed by this.

Here's the relevant portions of my advanced workflow. Any help would be appreciated.


…   
<start-state name="start">
      <task name="ygwf:startSurvey" swimlane="initiator" />
      <transition name="" to="draft" />
   </start-state>
   
   <swimlane name="author">
      <assignment
         class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
         <actor>#{ygwf_author}</actor>
      </assignment>
   </swimlane>

   <task-node name="draft">
      <task name="ygwf:draft" swimlane="author">
        <event type="task-assign">
             <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                <script>
               if(taskInstance.previousActorId != taskInstance.actorId) {
                  var mail = actions.create("mail");
                  
                  mail.parameters.to = ygwf_author.properties["cm:email"];
                  mail.parameters.subject = "You have been assigned a task.";
                  mail.parameters.from = initiator.properties["cm:email"];
                  mail.parameters.text = "You have been assigned to work on the following draft: " + bpm_workflowDescription;
               
                  mail.parameters.text += " taskInstance.previousActorId=["+taskInstance.previousActorId+"]";
                  mail.parameters.text += " taskInstance.actorId=["+taskInstance.actorId+"]";
                  mail.parameters.text += " taskInstance.previousActorId!=taskInstance.actorId = ["+(taskInstance.previousActorId!=taskInstance.actorId)+"]";
                  mail.execute(bpm_package);      
               }                            
                </script>
             </action>
          </event>
      </task>
      <transition name="" to="reviewDraft">
         <action
            class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               if (ygwf_notifyMe) {
                  var mail = actions.create("mail");
                  mail.parameters.to = initiator.properties["cm:email"];
                  mail.parameters.subject = "Survey Draft awaiting your review: " + bpm_workflowDescription;
                  mail.parameters.from = ygwf_author.properties["cm:email"];
                  mail.parameters.text = "The survey draft with description " + bpm_workflowDescription + " is now ready for review." ;
                  mail.execute(bpm_package);
               }
            </script>
         </action>
      </transition>
   </task-node>
   <task-node name="reviewDraft">
      <task name="ygwf:reviewDraft" swimlane="initiator" />
       <transition name="reject" to="draft" />
        <transition name="approve" to="assignEditor" />   
   </task-node>
   
…etc…
2 REPLIES 2

davidc
Star Contributor
Star Contributor
Which version of Alfresco are you using?

I'm sure a check is already made to ensure task-assign events are only fired when the actor id changes.

Where can I find this file?