cancel
Showing results for 
Search instead for 
Did you mean: 

Delete or Cancel Workflow programmatically in end state

sebp
Champ in-the-making
Champ in-the-making
I want all tasks from the "My Completed Tasks" dashlet to disappear as soon as a workflow is finished. Normally the user who initiated the workflow has to cancel it then the tasks disappear. I thought I could cancel or delete the workflow programmatically as part of the end-state task of the workflow itself, like this:

<end-state name="end">
<event type="node-enter">
    <action class="de.hmedia.alfresco.workflow.WfCancelHandler"/>
</event>
</end>

But this gives an sql error. I think this error occurs because the workflow is deleted within the same transaction that currently signals the end state of the workflow. Then I used the RetryingTransactionHelper to run the deletion of the workflow in a new transaction but this causes a dead-lock.
Is there any way to automatically delete the workflow (or remove the completed tasks of a workflow) as soon as the workflow is finished?
2 REPLIES 2

matjazmuhic
Champ on-the-rise
Champ on-the-rise
Have you tried this?


<event type="node-leave">

</event>

zaizi
Champ in-the-making
Champ in-the-making
Just modify the workflow to end on completion rather than assign a task to the initiator. Example below on how to do this with adhoc workflow.


   <task-node name="adhoc">
      <task name="wf:adhocTask" swimlane="assignee">
         <event type="task-create">
            <script>
               if (bpm_workflowDueDate != void) taskInstance.dueDate = bpm_workflowDueDate;
               if (bpm_workflowPriority != void) taskInstance.priority = bpm_workflowPriority;
            </script>
         </event>
      </task>
      <transition name="" to="end">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
           <script>
              if (wf_notifyMe)
              {
                 var mail = actions.create("mail");
                 mail.parameters.to = initiator.properties.email;
                 mail.parameters.subject = "Adhoc Task " + bpm_workflowDescription;
                 mail.parameters.from = bpm_assignee.properties.email;
                 mail.parameters.text = "It's done";
                 mail.execute(bpm_package);
              }
           </script>
         </action>
      </transition>
   </task-node>