cancel
Showing results for 
Search instead for 
Did you mean: 

how to get variable that are updated using VARIABLE_UPDATED event

ganeshr
Champ in-the-making
Champ in-the-making
I'm trying to listen to VARIABLE_UPDATED event and want to do some processing with the variables that are updated. For that I have implemented ActivitiEventListener and in the onEvent method trying to find the variables that are updated using the parameter variable ActivitiEvent,  but I dont see any methods in ActivitiEvent that can give that information.
Can you please let me know how to get the variables that are updated using the event handler. I tried in activiti user guide but I don't see anywhere or may be I'm missing.
4 REPLIES 4

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

org.activiti.engine.test.api.event.VariableEventsTest#testProcessInstanceVariableEventsevent.getVariableName();
  event.getVariableValue();

Regards
Martin

Does VARIABLE_UPDATED event will fire just as soon as any variable updated for process/task ? or does it have any exceptional cases where only on those cases it will fire? Because I was testing to listen to this event by updating the variable using the following call
taskService.setVariables(task.getId(), processVaraibles);
With the above call the variable values are getting updated but I'm not receiving any event.

Here is my configuration:
<code>
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
    <property name="dataSource" ref="dataSource" />
    <property name="databaseType" value="oracle" />
    <property name="transactionManager" ref="transactionManager" />
    <property name="databaseSchemaUpdate" value="false" />
    <property name="jobExecutorActivate" value="false" />
    <property name="enableDatabaseEventLogging" value="false" />
    <property name="idGenerator">
      <bean class="org.activiti.engine.impl.persistence.StrongUuidGenerator" />
    </property>
    <property name="typedEventListeners">
      <map>
        <entry key="VARIABLE_UPDATED" >
          <list>
             <ref bean="variableUpdateEventListner"/>
             <!–<bean class="com.uprr.netcontrol.workflow.event.listeners.VariableUpdateEventListener"></bean>
             –></list>
        </entry>
      </map>
    </property>
  </bean>
<code>

And listener class:
  <code>
     public class VariableUpdateEventListener implements ActivitiEventListener {

  protected static final transient Logger LOGGER = LoggerFactory.getLogger(VariableUpdateEventListener.class);

 

  private EventPublisher eventPublisher;

  @Override
  public final boolean isFailOnException() {
    return false;
  }

  @Override
  public final void onEvent(final ActivitiEvent event) {
    switch (event.getType()) {
    case VARIABLE_UPDATED:
      LOGGER.INFO("variable update event fired for process id {}", event.getProcessInstanceId());
      break;
    default:
      break;
    }

  }
}
  <code>

trademak
Star Contributor
Star Contributor
Are you sure it's variable update and not variable create?
If so, could you create a unit test showing the issue and create a JIRA issue for it?

Thanks,

ganeshr
Champ in-the-making
Champ in-the-making
Yes, it is for variable update.
I tried to reproduce by creating a unit test but there it is working. Might be guessing something wrong in my configuration