AnsweredAssumed Answered

timer events [SOLVED]

Question asked by jmuras on Feb 15, 2013
Latest reply on Oct 5, 2016 by shreejitray
Hi,

I try to create workflow that would send e-mails reminding about some task. I have created the following workflow:

<blockcode>

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:activiti="http://activiti.org/bpmn"
             xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
             xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
             xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"
             typeLanguage="http://www.w3.org/2001/XMLSchema"
             expressionLanguage="http://www.w3.org/1999/XPath"
             targetNamespace="http://alfresco.org">

    <process id="icmrSubmissionWorkflow" name="ICMR Artefact Submission Process" isExecutable="true">

        <startEvent id="start" activiti:formKey="icmrWf:submitArtefactTask"></startEvent>

        <sequenceFlow id="flow1" sourceRef="start" targetRef="reviewTask"></sequenceFlow>

        <userTask id="reviewTask" name="Review Task" activiti:formKey="icmrWf:reviewTask">
            <extensionElements>

                <!– Set canditate group for the task –>
                <activiti:taskListener event="create" class="ie.icmr.tacitknowledge.CandidateListener" />

                <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
                    <activiti:field name="script">
                        <activiti:string>
                            if (typeof bpm_workflowPriority != 'undefined') task.priority = bpm_workflowPriority;
                        </activiti:string>
                    </activiti:field>
                </activiti:taskListener>

                <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
                    <activiti:field name="script">
                        <activiti:string>
                            execution.setVariable('icmrWf_reviewOutcome', task.getVariable('icmrWf_reviewOutcome'));
                        </activiti:string>
                    </activiti:field>
                </activiti:taskListener>

            </extensionElements>

        </userTask>

        <sequenceFlow id="flow2" sourceRef="reviewTask" targetRef="reviewDecision"></sequenceFlow>

        <exclusiveGateway id="reviewDecision" name="Review Decision"></exclusiveGateway>

        <sequenceFlow id="flow3" sourceRef="reviewDecision" targetRef="approved">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${icmrWf_reviewOutcome == 'Approve'}]]></conditionExpression>
        </sequenceFlow>

        <sequenceFlow id="flow4" sourceRef="reviewDecision" targetRef="rejected"></sequenceFlow>

        <userTask id="approved" name="Document Approved" activiti:assignee="${initiator.exists() ? initiator.properties.userName : 'admin'}" activiti:formKey="icmrWf:approvedTask">
            <documentation>The document was reviewed and approved.</documentation>
            <extensionElements>

                <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
                    <activiti:field name="script">
                        <activiti:string>
                            if (typeof bpm_workflowPriority != 'undefined') task.priority = bpm_workflowPriority;
                        </activiti:string>
                    </activiti:field>
                </activiti:taskListener>

                <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
                    <activiti:field name="script">
                        <activiti:string>
                            execution.setVariable('bpm_assignee', person);
                        </activiti:string>
                    </activiti:field>
                </activiti:taskListener>

            </extensionElements>
        </userTask>

        <userTask id="rejected" name="Document Rejected" activiti:assignee="${initiator.exists() ? initiator.properties.userName : 'admin'}" activiti:formKey="icmrWf:rejectedTask">
            <documentation>The document was reviewed and rejected.</documentation>
            <extensionElements>

                <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
                    <activiti:field name="script">
                        <activiti:string>
                            if (typeof bpm_workflowPriority != 'undefined') task.priority = bpm_workflowPriority;
                        </activiti:string>
                    </activiti:field>
                </activiti:taskListener>

                <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
                    <activiti:field name="script">
                        <activiti:string>
                            execution.setVariable('bpm_assignee', person);
                        </activiti:string>
                    </activiti:field>
                </activiti:taskListener>

            </extensionElements>
        </userTask>

        <sequenceFlow id="flow5" sourceRef="approved" targetRef="end"></sequenceFlow>

        <sequenceFlow id="flow6" sourceRef="rejected" targetRef="end"></sequenceFlow>

        <endEvent id="end"></endEvent>

        <boundaryEvent id="timer" name="Timer" attachedToRef="reviewTask" cancelActivity="true">
            <timerEventDefinition>
                <!– Fire remainder every monday at 8 am –>
                <!–<timeCycle>0 0 8 ? * MON</timeCycle>–>
                <!–<timeCycle>0 * * ? * *</timeCycle>–>
                <timeDuration>PT2M</timeDuration>
            </timerEventDefinition>
        </boundaryEvent>

        <serviceTask id="mailtask" name="Email Reminder" activiti:class="org.alfresco.repo.workflow.activiti.script.AlfrescoScriptDelegate">
            <extensionElements>
                <activiti:field name="script">
                    <activiti:string>
                        logger.log("Send e-mail");
                    </activiti:string>
                </activiti:field>
            </extensionElements>
        </serviceTask>

        <sequenceFlow id="flow7" sourceRef="timer" targetRef="mailtask"></sequenceFlow>

        <sequenceFlow id="flow8" sourceRef="mailtask" targetRef="reviewDecision"></sequenceFlow>

    </process>

    <bpmndi:BPMNDiagram id="BPMNDiagram_icmrSubmissionWorkflow">
        <bpmndi:BPMNPlane bpmnElement="icmrSubmissionWorkflow" id="BPMNPlane_icmrSubmissionWorkflow">
            <bpmndi:BPMNShape bpmnElement="start" id="BPMNShape_start">
                <omgdc:Bounds height="35.0" width="35.0" x="30.0" y="200.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="reviewTask" id="BPMNShape_reviewTask">
                <omgdc:Bounds height="55.0" width="105.0" x="180.0" y="189.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="reviewDecision" id="BPMNShape_reviewDecision">
                <omgdc:Bounds height="40.0" width="40.0" x="570.0" y="196.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="approved" id="BPMNShape_approved">
                <omgdc:Bounds height="55.0" width="105.0" x="680.0" y="96.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="rejected" id="BPMNShape_rejected">
                <omgdc:Bounds height="55.0" width="105.0" x="680.0" y="295.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="end" id="BPMNShape_end">
                <omgdc:Bounds height="35.0" width="35.0" x="845.0" y="199.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="timer" id="BPMNShape_timer">
                <omgdc:Bounds height="30.0" width="30.0" x="250.0" y="229.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="mailtask" id="BPMNShape_mailtask">
                <omgdc:Bounds height="55.0" width="105.0" x="212.0" y="296.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
                <omgdi:waypoint x="65.0" y="217.0"></omgdi:waypoint>
                <omgdi:waypoint x="180.0" y="216.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
                <omgdi:waypoint x="285.0" y="216.0"></omgdi:waypoint>
                <omgdi:waypoint x="570.0" y="216.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
                <omgdi:waypoint x="590.0" y="196.0"></omgdi:waypoint>
                <omgdi:waypoint x="590.0" y="123.0"></omgdi:waypoint>
                <omgdi:waypoint x="680.0" y="123.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
                <omgdi:waypoint x="590.0" y="236.0"></omgdi:waypoint>
                <omgdi:waypoint x="590.0" y="323.0"></omgdi:waypoint>
                <omgdi:waypoint x="680.0" y="322.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
                <omgdi:waypoint x="785.0" y="123.0"></omgdi:waypoint>
                <omgdi:waypoint x="862.0" y="123.0"></omgdi:waypoint>
                <omgdi:waypoint x="862.0" y="199.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
                <omgdi:waypoint x="785.0" y="322.0"></omgdi:waypoint>
                <omgdi:waypoint x="862.0" y="323.0"></omgdi:waypoint>
                <omgdi:waypoint x="862.0" y="234.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">
                <omgdi:waypoint x="317.0" y="323.0"></omgdi:waypoint>
                <omgdi:waypoint x="589.0" y="322.0"></omgdi:waypoint>
                <omgdi:waypoint x="590.0" y="236.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
                <omgdi:waypoint x="265.0" y="259.0"></omgdi:waypoint>
                <omgdi:waypoint x="264.0" y="296.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
        </bpmndi:BPMNPlane>
    </bpmndi:BPMNDiagram>
</definitions>

</blockcode>

Timer event is defined as


<boundaryEvent id="timer" name="Timer" attachedToRef="reviewTask" cancelActivity="true">


Ideally I would like to run reminders every period of time, for example every minute:


<timeCycle>0 * * ? * *</timeCycle>


But unfortunately it does not work and runs only once. I also tired to use subprocess, but without success. When I run timer only once with for example 2 minutes delay


<timeDuration>PT2M</timeDuration>


'mailtask' runs 3 times. This happens also for timeCycle tag.

In addition, I get the following exception

Caused by: org.activiti.engine.impl.javax.el.PropertyNotFoundException: Cannot resolve identifier 'icmrWf_reviewOutcome'

I know what causes that icmrWf_reviewOutcome variable is set only in reviewTask but where should I connect reminder branch back after mailtask is done. I tried to connect it back to timer, but then timer fires instantly. I tried not to connect it to anything but then workflow is being finished.

Did someone face similar issue? Any ideas how to deal with it?

Regards,
Joanna Muras


Outcomes