Get ExecutionVariable from Async Service task

Hi All,

I am new to Camunda, trying to write unit test where i am trying to access the variable in the delegate which is configured AsyncBefore:true, I was able to access all the variables from DelegateExecution prior to this AsyncBefore service task but not after this async before. could you please let me know if there any options to retreive those values
I am using spring-boot and here is my sample code to get all the variable
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(
“TestProcess”);
Map<String, Object> vars = runtimeService.getVariables(processInstance.getId());

What exactly happens when you ask for variables after the execution of your service task?
Can you upload you model and the full unit test?

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("TestProcess");

    String content = null;
    while (!processInstance.isEnded()) {
        Thread.sleep(500);
        Map<String, Object> vars = runtimeService.getVariables(processInstance.getId());
        content = (String) vars.get("CONTENT");
        if (isNotBlank(content)) {
            break;
        }

    }

When i access any variable after the serviceTask which is configured asyncBefore:true, I get null values…however i can access any delegates variables from different service task before this async flow.

Can you upload your process model as well?

I am unable to upload, it says new user can upload only 2 links

Is there any other option to upload this?

You can upload in github and share the GitHub link or share it via camunda cloud cawemo.com (better)

Here is the github url for model

@Niall @aravindhrs - could you please let me know what is missing in my test to read variables from asynchronous continuations (asyncBefore) service task? really appreciate your help

If this is a unit test, it is likely the job executor thread is not running. So the process job waits at the async before call, and does not execute the task until you “manually” progress it by something like -
Job job = engine.getManagementService().createJobQuery().singleResult();
assertNotNull(job);
engine.getManagementService().executeJob(job.getId());

After this call, the current thread will pick up the token and execute the task, stopping again at the next wait state. At that point, the variables should be stored again, and accessible.

Hopefully this makes sense

I have come up with similar issue , this is my model

parallelRollback.bpmn (18.9 KB)

I am trying to access the variable which is set in Confirm Transaction service task which is executed in background as there are asyncBefore = true tasks marked in the previous steps ( Loyalty , CC payment )

I am setting the variable in ConfirmTransactionWorker like this

ctx.setVariable( "SUCCESS", true );
System.out.println( "Ctx var SUCCESS set to " + (boolean) ctx.getVariable( "SUCCESS" ) );

And it is being set also , but the scope of this variable is not visible when i access in application thread where this processinstance is initiated

 try
      {
         ProcessInstanceWithVariables processInstance = runtimeService.createProcessInstanceByKey( OrchestrationConstants.MAKE_PAYMENT_PROCESS_KEY ).setVariable( OrchestrationConstants.DATA_ACCESSOR, multiTenderPaymentDataAccessor )
                  .executeWithVariablesInReturn();

         
         System.out.println( "outside invocation" );
         
         while(!processInstance.getVariables().containsKey( "SUCCESS" ))
         {
            
         }
         
         System.out.println( "execution  ended" );
         return null;
      }

In the while loop above only the variable which is set during instantiation of process and one which was set in Start Transaction are visible but not the variable set in Confirm Transaction