cancel
Showing results for 
Search instead for 
Did you mean: 

Timer Boundary Event and User task assignee

vincent-kali
Star Contributor
Star Contributor

I want to send an email reminder to each user task assignee (multiinstance task) after a given period a time. A Timer Event is bound to the user task and triggers a service task (AlfrescoScriptDelegate) that should send an email to the user task assignee.

My problem/question:

   Task object is not available in AlfrescoScriptDelegate context, and I don't know how to get the userTask assignee.

My code: 

<code>

    <userTask id="buyerApprovalLevel1Task" name="Buyer approval level 1 user task" activiti:assignee="${buyerApprovalLevel1Assignee.properties.userName}" activiti:formKey="supplierinvoice:buyerApprovalLevel1Task">
      <documentation>Buyer approval level 1 user task</documentation>
      <multiInstanceLoopCharacteristics isSequential="false" activiti:collection="supplierinvoice_buyerApprovalLevel1Assignees" activiti:elementVariable="buyerApprovalLevel1Assignee">
        <completionCondition>${wf_buyerApprovalLevel1TaskOutcome != 'NONE'}</completionCondition>
      </multiInstanceLoopCharacteristics>
    </userTask>

    <boundaryEvent id="buyerApprovalLevel1TaskTimer" name="Timer" attachedToRef="buyerApprovalLevel1Task" cancelActivity="false">
      <timerEventDefinition>
        <timeCycle>${wf_reminderCronExpression}</timeCycle>
      </timerEventDefinition>
    </boundaryEvent>
    <sequenceFlow id="flowBuyerApprovalLevel1TaskTimerOut" sourceRef="buyerApprovalLevel1TaskTimer" targetRef="buyerApprovalLevel1Reminder"></sequenceFlow>
    <serviceTask id="buyerApprovalLevel1Reminder" name="Buyer approval level1 email reminder" activiti:class="org.alfresco.repo.workflow.activiti.script.AlfrescoScriptDelegate">
      <extensionElements>
        <activiti:field name="runAs">
          <activiti:string><![CDATA[wfservice-supplierinvoice]]></activiti:string>
        </activiti:field>
        <activiti:field name="script">
          <activiti:string><![CDATA[
    
    ?? task object is not available here, how to get userTask assignee ??
    
    ]]></activiti:string>
        </activiti:field>
      </extensionElements>
    </serviceTask>

</code>

Thanks for your help.

Vincent

4 REPLIES 4

afaust
Legendary Innovator
Legendary Innovator

There is no task because you are not executing a task listener - only the ScriptTaskListener class will have the "task" variable set as a global variable in JavaScript. Also, you could not have accessed the assigned user from the task variable anyway, since the task you are executing the JavaScript in isn't a user task (it is a service task) and as such does not have an assignee. You would need to execute a task query via the low-level Activiti RuntimeService to find and access the user task to which your boundary event is attached.

Thanks axel, very clear.

So is there any simple way to send a reminder email to user task assignee after a given period of time ?

afaust
Legendary Innovator
Legendary Innovator

If you are asking "so simple I don't have to code anything", then no. Otherwise it is quite easy - implement your JavaScript service delegate, use the root scope object "workflows" (WorkflowManager) to query for active tasks in the current workflow - maybe filter for the previous task ID if you have parallel execution paths - and then use the email action to send the mail. For an easy implementation the Alfresco "workflows" root scope object may suffice - I usually don't use it because it hides quite a bit of information that I usually need, but for a reminder you may not need such internals...

vincent-kali
Star Contributor
Star Contributor

Ok thanks I'll try this way.

Just one thing: could you please explain "maybe filter for the previous task ID if you have parallel execution paths" ?

(I'm not 100% sure how to deal with paths to get previous task...)