Error while completing User Task

My workflow has two process instances(A & B) .Process A has a User Task and then a service task , after completion of this , flow goes to Process B’s service task ,where variables passed from User Task in Process A are accessed. But I am getting “null” in execution.getvariable(“x”) .
Although all processes have in & out variables set as “all”

This scenario works sometimes , but gives error most of the times.

Please suggest.
@Niall - Need help please.

@Sonali could you provide the bpmn file? It might be cause of the variables set in usertask was not saved in the db during service task execution if it’s execution is synchronous. By setting asyn before flag for service task might solve the issue

Thanks @aravindhrs !
I tried to set async before = true in the previous and subsequent tasks , but no luck.
Here is the part of bpmn flow

which is having issue .

ABC → Approve → XYZ → Reject → ABC → Reject ->Error in Completing task in ABC Process.

Note: ABC , XYZ , XX processes have service task and user task inside them.

You are using call activities to call a separate process model for the sub processes. Each time you enter a call activity, a new process instance will be spawned, with a completely isolated set of variables. In order to ensure that the second execution of ABC has access to variables created or used in the first execution, you need to explicitely map the inputs and outputs to/from the call activities and the main process.

Thanks @tiesebarrell for response . Just to confirm you mean mapping of input /output variables like below ?

Also , I have observed (its bit weird) , sometimes the flow I have mentioned works , sometimes it doesn’t . Is it related to threads ?

Yes, that’s what I meant. But I see now that you mentioned you already map them all.

It could be related to threads. To figure out if it is, I’d suggest marking the call activities and the start events of those subprocesses as async before. That would prevent a sub process from trying to access something that’s mapped in, but maybe not available at the higher level.

Ok I will try that . But I could not understand below .

"That would prevent a sub process from trying to access something that’s mapped in, but maybe not available at the higher level. "

The variables are mapped from one execution to the other. If something is not persisted yet, you might have an empty result when resolving it.