AnsweredAssumed Answered

Execution of listeners does not capture values

Question asked by alexsimas on Nov 13, 2016
Latest reply on Nov 16, 2016 by alexsimas
Hello peoples!

I've been trying for a few days to run listeners in a process with no success. I've done enough research and nothing.

See my code below:

package br.simas.process.listener;

import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;

public class MyExecutionListener implements ExecutionListener {
   
   private static final long serialVersionUID = 1L;

   @Override
   public void notify(DelegateExecution execution) throws Exception {
      // TODO Auto-generated method stub

      try {

         execution.setVariable("initiator", execution.getEngineServices()
               .getHistoryService()
               .createNativeHistoricProcessInstanceQuery().singleResult()
               .getStartUserId());

               // debug information
         System.out.println("Id corrente: "
               + execution.getCurrentActivityId());
         System.out.println("A definição do processo é: "
               + execution.getProcessDefinitionId());
         System.out.println(" O id da instância é: "
               + execution.getProcessInstanceId());

      } catch (NullPointerException e) {
         System.out.println(" O problema é " + e.getMessage());
      }
   }
}

The problem is that it always returns NULL.

I'm new to Activiti and I'm still studying a lot, what I want is to just capture the user who started the process instance, write that value to a variable and then use listener tasks to do the assignment capturing this variable, both for itself and for Your immediate superior through a SQL query.

If you have a simpler way to capture this variable would be interesting.

Can someone help me?

Outcomes