BPMN Process variables created in Expression Delegate not visible in BPMN

Hi,
I am not sure what I am doing wrong.
First of all, I am working with a shared Camunda engine (7.14).
I have a spring application (war-file), in this application, I have several JavaDelegate Classes (Spring Components) defined. These classes are referenced in my BPMN ${beanName} as “Expression Delegates”. It works fine, the classes are executed as expected. Inside these classes, I am setting process variables e.g. execution.setVariable(“updateExecuted”, 1); and the values of these variables are not visible inside the BPMN which has called the bean. I need them for executing the gateways #{updatedExecuted==1}.
The values of the process variables are always null inside the BPMN. The variables are in the list of variables execution.getVariables() but the values are not set.
Any idea
Best Regards
Edmund

Hi @Edmund
Welcome to the forum!

Can you upload your model and maybe also the code which sets the variable?

Hi Niall,
I cannot upload my Java file, so I will integrate it into the message
Class CheckDB.java:
package eu.ecb.mora.scheduler;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import javax.sql.DataSource;

import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.camunda.bpm.engine.variable.Variables;
import org.camunda.bpm.engine.variable.impl.value.NullValueImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component(“checkDB”)
public class CheckDB extends AbstractDatabaseAccessService implements JavaDelegate {
public static final Logger LOGGER = LoggerFactory.getLogger(CheckDB.class);
public static final String QUERY = “SELECT * from databasetable”;

@Override
public void execute(DelegateExecution execution) throws Exception {

    LOGGER.debug("enter execution of CheckDB");

    Object v1 = execution.getVariableTyped("DateOfDBLastUpdate");
    execution.setVariable("DBUpdated", Variables.integerValue(0));

    Date dbLastUpdatedDate = null;
    if (!(v1 instanceof NullValueImpl) && v1 instanceof Date) {
        dbLastUpdatedDate = (Date) v1;
    }
    Integer dbUpdated = 0;

    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet result = null;
    try {
       execution.setVariable("DateOfDBLastUpdate", new Date());
       dbUpdated = 1;
       execution.setVariable("DBUpdated", Variables.integerValue(dbUpdated));
	   
	   ...
	   
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
		closing(con, pstmt, result);
    }
    LOGGER.debug("DBUpdated:" + execution.getVariable("DBUpdated"));
    LOGGER.debug("DateOfDBLastUpdate:" + execution.getVariable("DateOfDBLastUpdate"));
}

}

CheckDBProcess.bpmn (10.4 KB)

I can see the values of the Variables inside the class but they are not accessible in the gateway expression in the BPMN and not listed in the logger output of the LoggerDelegate class.

Regards
Edmund

@Edmund, In the gateway expression you were referring the variable #{RARupdated==1} , but in the delegate you’re setting DBUpdated variable

execution.setVariable("DBUpdated", Variables.integerValue(dbUpdated))

Anyway, to access the fields been setting in the delegate and to use that variables in the gateway expression, you need to put save point at the exclusive gateway, so the variables will be persists and will be available for further activities.

Thanks, this little click solved my problem.

1 Like