cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass all parent variables to a called process

blezek
Champ on-the-rise
Champ on-the-rise
In a sub process, all the parent workflow variables are accessible, however, in a called process, each variable must be explicitly passed.  We are not so concerned with variables returned from the called process.  Is there an easy way to pass all variables from the parent into the called process?  We like the isolation provided by a sub-process, but desire the reuse provided by a called process.

Thanks,
-dan
2 REPLIES 2

blezek
Champ on-the-rise
Champ on-the-rise
Found an answer, thought I'd post for others to use.  In the called process, define a start event listener that looks up the super execution and pulls all the variables local.  Very handy and easy.

<code>
public class WorkflowVariableInjectorListener implements ExecutionListener {
  private static final long serialVersionUID = 1L;

  static Logger logger = Logger.getLogger(WorkflowVariableInjectorListener.class);

  @Override
  public void notify(DelegateExecution execution) throws Exception {
    logger.info("In notify");
    if (execution instanceof ExecutionEntity) {
      ExecutionEntity executionEntity = (ExecutionEntity) execution;
      ExecutionEntity parentEntity = executionEntity.getSuperExecution();
      if (parentEntity != null) {
        // Copy all the variables into me
        executionEntity.setVariables(parentEntity.getVariables());
      }
    }

  }

}
</code>

jbarrez
Star Contributor
Star Contributor
That is a smart solution. Thanks for sharing it!