AnsweredAssumed Answered

Advanced Workflow : task-assign + Task Done

Question asked by timothy.michael.clark on May 8, 2007
Latest reply on Oct 6, 2015 by jeanmartinelli
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" />
   <swimlane name="author">

   <task-node name="draft">
      <task name="ygwf:draft" swimlane="author">
        <event type="task-assign">
             <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               if(taskInstance.previousActorId != taskInstance.actorId) {
                  var mail = actions.create("mail");
                  mail.parameters.subject = "You have been assigned a task.";
                  mail.parameters.from =["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)+"]";
      <transition name="" to="reviewDraft">
               if (ygwf_notifyMe) {
                  var mail = actions.create("mail");
                  mail.parameters.subject = "Survey Draft awaiting your review: " + bpm_workflowDescription;
                  mail.parameters.from =["cm:email"];
                  mail.parameters.text = "The survey draft with description " + bpm_workflowDescription + " is now ready for review." ;
   <task-node name="reviewDraft">
      <task name="ygwf:reviewDraft" swimlane="initiator" />
       <transition name="reject" to="draft" />
        <transition name="approve" to="assignEditor" />