title: Alfresco workflows and email notifications
body: <p>I have written a custom JBPM workflow that for some tasks has to send notifications to the assigned users.</p>
  
  <p>I know how to do it using a custom java action or a simple javascript, but I am trying to use the flag bpm_sendEMailNotifications: if this flag is true, the class org.alfresco.repo.workflow.jbpm.AlfrescoAssignment automatically sends the notifications using the utility class org.alfresco.repo.workflow.WorkflowNotificationUtils.</p>
  
  <p>For example, the following task in my workflow definition sets the flag to true on the creation of the task.</p>
  
  <pre><code>&lt;task-node name="finalReview"&gt;
      &lt;task name="mswf:reviewTask"&gt;
          &lt;assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment"&gt;
             &lt;pooledactors&gt;#{finalReviewReviewer}&lt;/pooledactors&gt;
          &lt;/assignment&gt;
          &lt;event type="task-create"&gt;
              &lt;script&gt;
                  executionContext.setVariable("bpm_sendEMailNotifications", true);
              &lt;/script&gt;
          &lt;/event&gt;
      &lt;/task&gt;
      &lt;transition name="approve" to="endFinalReview"/&gt;
      &lt;transition name="reject" to="endFinalReview"/&gt;
  &lt;/task-node&gt;
  </code></pre>
  
  <p>Because, when the task is assigned, this flag is true, AlfrescoAssignment tries to send the notifications.</p>
  
  <p>Unfortunately, the transition to this task node fails with the following exception:
  "07052361 Accessing task with id='jbpm$200957' is not allowed for user 'atc1'"</p>
  
  <p>atc1 is the user that clicks the transition button and it is not the current user assigned to the task.</p>
  
  <p>The exception is thrown by the class WorkflowNotificationUtils when it tries to get the WorkflowTask (at line 168 for Alfresco enterprise version 4.1.7 that is the first line of the method sendWorkflowAssignedNotificationEMail() ):</p>
  
  <pre><code>WorkflowTask workflowTask = services.getWorkflowService().getTaskById(taskId);
  </code></pre>
  
  <p>I verified that the task has been already assigned to a different user, as expected.</p>
  
  <p>I hope that somebody knows what is wrong with this solution. In the mean time, I will try to use this flag with a vanilla workflow to see if it fails as well. </p>