AnsweredAssumed Answered

Is it possible to create a local task variable on a completion event?

Question asked by robojeff on Nov 4, 2016
Latest reply on Feb 27, 2017 by gdharley
I'd like to create a local task variable from a TaskListener when Activiti invokes it for a "complete" event:


public class RoutingOptionAuditor implements TaskListener {
    private Expression routeExpression;

    @Override
    public void notify(DelegateTask delegateTask) {
        String routingOption = getRoutingOption(delegateTask); // this code grabs some text from an enumerated form property value

        TaskService taskService = getTaskService(delegateTask);
        taskService.setVariableLocal(delegateTask.getId(), "routingOption", routingOption);
}


This code causes a SQL Exception:


### Error updating database.  Cause: org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: "ACT_FK_VAR_EXE: PUBLIC.ACT_RU_VARIABLE FOREIGN KEY(EXECUTION_ID_) REFERENCES PUBLIC.ACT_RU_EXECUTION(ID_) ('5')"; SQL statement:
delete from ACT_RU_EXECUTION where ID_ = ? and REV_ = ? [23503-192]
### The error may involve org.activiti.engine.impl.persistence.entity.ExecutionEntity.deleteExecution-Inline
### The error occurred while setting parameters
### SQL: delete from ACT_RU_EXECUTION where ID_ = ? and REV_ = ?
### Cause: org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: "ACT_FK_VAR_EXE: PUBLIC.ACT_RU_VARIABLE FOREIGN KEY(EXECUTION_ID_) REFERENCES PUBLIC.ACT_RU_EXECUTION(ID_) ('5')"; SQL statement:
delete from ACT_RU_EXECUTION where ID_ = ? and REV_ = ? [23503-192]


Does the "complete" TaskListener event occur too late in the task's lifecycle to be adding local task variables to it?  If so, is there a recommended technique for trying to do this?

Outcomes