Search code examples
interceptoractiviti

Retrieve executionId inside CommandInterceptor


I am implementing my own Activiti command intereceptor like this :

public class ActivitiCommandInterceptor extends AbstractCommandInterceptor {
    private RuntimeService runtimeService;
    private CommandInterceptor delegate;

    public ActivitiSpringTxCommandInterceptor(RuntimeService runtimeService, CommandInterceptor delegate) {
        this.runtimeService = runtimeService;
        this.delegate=delegate;
    }

    @Override
    public <T> T execute(CommandConfig config, Command<T> command) {
        String myVariable = runtimeService.getVariable(<missingExecutionId>, "myVariableName");

        ...
    }
}

Inside the execute() method I need to retrieve a variable from the execution context related to this command.

To do that, I need to have the executionId, but I can't find a way to retrieve it.

How can I get my variable from this interceptor?

Thanks


Solution

  • You can create a nativeExecutionQuery This allows us to use SQL to perform operations directly on DB.

    For your case, just find all the execution IDs that contains your variables, and filter them according to your need.