cancel
Showing results for 
Search instead for 
Did you mean: 

Ending a userTask from a TimerEvent using the task.endTask(transitionId) method

darkredd1
Champ in-the-making
Champ in-the-making
Hi to all,

I am working on a workflow that has a multiInstance process, I have a requirement to escalate a task if not complete in time (specified).
I am using a timerEvent to trigger this action. However, the task does not end using the endTask() method. Here is a snippet code of what we are working on:

<blockcode>
<scriptTask id="reminderMail">
       <extensionElements>
          <activiti:executionListener event="start" class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener">
             <activiti:field name="script">
                <activiti:string>
                   var workDef = workflow.getDefinitionByName("activiti$submissionWorkflow");
            
                   var instances = workDef.getActiveInstances();
                  
                  var taskid = "activiti$" + execution.getVariable('recotaskId');
                  
                  var instance = instances[0];
                  var paths = instance.paths;
                  
                  var alltasks = paths[0].tasks;
                  execution.setVariable('sita_reviewOutcome', "Recommend");
                  paths[0].signal("Next");
                  var counter = alltasks[0].transitions;

                  logger.log(alltasks[0].name + " task name kkkkkkkkkkkkkkkkkkk");
                  alltasks[0].endTask("Next");
                </activiti:string>
             </activiti:field>
          </activiti:executionListener>
       </extensionElements>
    </scriptTask>
</blockcode>

Our multi-Instance task has two possible outcomes: Recommend or Reject; which leads an exclusive gateway to assess the decision.
What we get is an error about the transaction failing because it does not know where to go after the endTask method.

Thanks for the help in advance

Regards
DarkRedd
5 REPLIES 5

frederikherema1
Star Contributor
Star Contributor
What do you mean by "it does not know where to go after the endTask method"? You shouldn't signal the paths yourself from within the workflow, this will not work. Completing a task from within the flow (executionListener) will cause issues because you try to influence the process flow.

What is the use case of this alfresco-process. What do you want to do with the task when the timer fires?

darkredd1
Champ in-the-making
Champ in-the-making
Hi frederikheremans,

Thanks for the reply.

What needs to happen when the timer fires is to close that respective task and move to the next task inline. This is an escalation process, if a user does not complete his task within the given time, they are escalated to a higher level (manager or supervisor).

As I read on the use of the endTask() method, it is supposed to close a task and continue with the flow.

I hope this help give you a picture of what I need to do.

Regards
DarkRedd

darkredd1
Champ in-the-making
Champ in-the-making
Hi,

Additional information about the error I'm getting:

ERROR [org.springframework.transaction.support.TransactionSynchronizationUtils] TransactionSynchronization.afterCompletion threw exception
java.lang.IllegalStateException: No value for key [org.apache.ibatis.session.defaults.DefaultSqlSessionFactory@862cb1] bound to thread [pool-5-thread-1]
at org.springframework.transaction.support.TransactionSynchronizationManager.unbindResource(TransactionSynchronizationManager.java:199)
at org.mybatis.spring.SqlSessionUtils$SqlSessionSynchronization.suspend(SqlSessionUtils.java:243)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.doSuspendSynchronization(AbstractPlatformTransactionManager.java:666)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.suspend(AbstractPlatformTransactionManager.java:569)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.handleExistingTransaction(AbstractPlatformTransactionManager.java:418)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:347)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:127)
at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40)
at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
at org.activiti.engine.impl.jobexecutor.DecrementJobRetriesListener.execute(DecrementJobRetriesListener.java:38)
at org.activiti.spring.SpringTransactionContext$4.afterCompletion(SpringTransactionContext.java:82)
at org.springframework.transaction.support.TransactionSynchronizationUtils.invokeAfterCompletion(TransactionSynchronizationUtils.java:168)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.invokeAfterCompletion(AbstractPlatformTransactionManager.java:996)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerAfterCompletion(AbstractPlatformTransactionManager.java:971)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:874)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:822)
at org.springframework.transaction.support.TransactionTemplate.rollbackOnException(TransactionTemplate.java:161)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:134)
at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40)
at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
at org.activiti.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:36)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)

The about exception is thrown after the timer fires.

Regards

frederikherema1
Star Contributor
Star Contributor
If the boundary-timer event has a "cancelActivity = true", the task will be automatically ended/deleted. Will the other multi-instance task keep on running? That case, you should model a sub-process containing the escalation-chain (task1 with boundry-timer -> escalated task). That subprocess is that equipped with "multi-instance" characteristics, so the whole "escalation chain" is repeated instead of the initial task.

So you do NOT end tasks yourself, you rely on activiti to do this… Does this make sense?

darkredd1
Champ in-the-making
Champ in-the-making
It makes a lot of sense. Let me try out your suggestion and see if we can get it going.

Thanks for the reply.