cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with 'Use of Timer' in Workflow

yogesh_prabhu
Champ in-the-making
Champ in-the-making
Hi,

I am working with Alfresco EE 3.2r.

I have implemented a timer on a multilevel workflow.
For Example: There are 2 assignees 'A' and 'B'. If 'A' does not approve in a stipulated time the workflow is assigned to 'B'

Now, the timer expires and the workflow moves to 'B', however 'A' is still able to see the task in 'My Tasks to do' list..Can it be moved to 'My completed tasks'??

Here is the processdefinition.xml that i am using:

<?xml version="1.0" encoding="UTF-8"?>

<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="wfl:lifecycleapproval">

    <swimlane name="initiator" />

    <start-state name="start">
        <task name="wf:submitReviewTask" swimlane="initiator" />

        <event type="node-leave">
            <!– Call script once the workflow package exists i.e. on node-leave –>
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                <!– Apply the Workflow Lifecycle Aspect (wfl:status) if not set already. Note: The default wfl:status property is draft –>
                <script>
         
                    for (var i = 0; i &lt; bpm_package.children.length; i++)
                    {
                       if (!bpm_package.children[i].hasAspect("wfl:status"))
                       {
               
                          bpm_package.children[i].addAspect("wfl:status");
                       }
                    }
                </script>
            </action>
        </event>

        <transition name="" to="review" />
    </start-state>

    <swimlane name="reviewer">
       <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
          <actor>#{bpm_assignee}</actor>
       </assignment>
    </swimlane>
   
   <swimlane name="senior-reviewer">
       <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
          <actor>#{bpm_assignee1}</actor>
       </assignment>
    </swimlane>


    <task-node name="review">
        <event type="node-enter">
            <!– Update the status to In Review when we enter this task –>
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                <script>
         
                    for (var i = 0; i &lt; bpm_package.children.length; i++)
                    {
                       bpm_package.children[i].properties["wfl:status"] = "In Review";
                       bpm_package.children[i].save();
                    }
                </script>
            </action>
        </event>

        <task name="wf:reviewTask" swimlane="reviewer">
            <event type="task-create">
                <script>
                    if (bpm_workflowDueDate != void) taskInstance.dueDate = bpm_workflowDueDate;
                    if (bpm_workflowPriority != void) taskInstance.priority = bpm_workflowPriority;
                </script>
            </event>
        </task>
         <timer name="thirdPartyTimer" duedate="2 minutes" transition="approve">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
         <script>
            logger.log("Timer Expired");
         </script>
      </action>
     </timer>
        <transition name="reject" to="rejected"/>
        <transition name="approve" to="senior-review"/>
    </task-node>

<task-node name="senior-review">

       <task name="wf:reviewTask" swimlane="senior-reviewer"/>

      <transition name="approve" to="approved">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
<script>
var departmentSpace = companyhome.childByNamePath("Employee/Old");
var department=departmentSpace.childByNamePath(bpm_id);
var dest=companyhome.childByNamePath("Employee/Old"); 

if (department==null)
{
         bpm_context.move(dest);
      
}
      </script>


      </action>
      </transition>
      <transition name="reject" to="rejected"/>
   </task-node>


    <task-node name="rejected">
        <event type="node-enter">
            <!– Update the status to Draft when we enter this task –>
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                <script>
                    for (var i = 0; i &lt; bpm_package.children.length; i++)
                    {
                       bpm_package.children[i].properties["wfl:status"] = "Draft";
                       bpm_package.children[i].save();
                    }
                </script>
            </action>
        </event>

        <task name="wf:rejectedTask" swimlane="initiator" />
        <transition name="" to="end" />
    </task-node>
    <task-node name="approved">
        <event type="node-enter">
            <!– Update the status to Approved when we enter this task –>
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                <script>
         

                    for (var i = 0; i &lt; bpm_package.children.length; i++)
                    {
                       bpm_package.children[i].properties["wfl:status"] = "Approved";
                       bpm_package.children[i].save();
                    }
                </script>
            </action>
        </event>

        <task name="wf:approvedTask" swimlane="initiator" />
        <transition name="" to="end" />
    </task-node>

    <end-state name="end" />

    <event type="process-end">
        <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
   

                if (cancelled)
                {
                    for (var i = 0; i &lt; bpm_package.children.length; i++)
                    {
                       if (bpm_package.children[0].hasAspect("wfl:status"))
                       {
                          bpm_package.children[i].properties["wfl:status"] = "Draft";
                          bpm_package.children[i].save();
                       }
                    }
                    if (logger.isLoggingEnabled()) logger.log("Workflow cancelled, status reset to Draft");
                }
                else               
                {
                    if (logger.isLoggingEnabled()) logger.log("Workflow completed");
                }
            </script>
        </action>
    </event>

</process-definition>

Is there a solution or idea on this..?

Any kind of suggestions are welcome..

Thanks in advance..
2 REPLIES 2

solo8788
Champ in-the-making
Champ in-the-making
This is a known bug, will be fixed on 3.3

https://issues.alfresco.com/jira/browse/ALF-2629

gyro_gearless
Champ in-the-making
Champ in-the-making
Not sure if this matches your case, but i had a similar problem lately when i wanted to have a <tasknode> that auto-completes itself.
I suppose it is not enough to trigger the leaving transition, you also have to explicitly finish the task.
Here is a small snippet of Javascript, maybe you can make use of that:

        <event type="task-create">
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                <script>
                    logger.log("record-completion::task-create");
                    token = taskInstance.token;
                    logger.log("Token is "
                    + token);
                    lockOwner = token.lockOwner;
                    logger.log("Lock owner is " + lockOwner);
                    token.unlock(lockOwner);
                    logger.log("***
                    Token
                    unlocked ***");
                    taskInstance.end("finalize");
                    logger.log("*** Task ended ***");
               </script>
            </action>
        </event>


Here i used the "task-create" event, but possibly this works from a timer, too….

HTH
Gyro