Streams

Integration Builder – Sub-Flow Example

Sub-flows are an Axway Integration Builder step type. Sub-flows are useful to encapsulate functionality in a reusable component (flow) and help you create DRY flows (Don’t Repeat Yourself). They are basically flows that are called from another flow and can be viewed as a function.

In this blog post we’ll review the steps to create and use a sub-flow in another flow as well as how to pass in variables and arguments and access the sub-flow response.

The basic steps are as follows:

  • Create your sub-flow as you would any flow and set the trigger type to manual; you don’t need to create a flow instance.
  • The sub-flow can access any passed in arguments using trigger.args and config.varName
  • Create your parent flow and use the sub-flow step to incorporate your sub-flow into your parent step
  • The parent step should prepare the arguments and any variables to pass into the sub-flow in a step prior to the sub-flow step
  • The parent flow can access the response of the sub-flow

Sub-flow

A simple flow, which we’ll use as a sub-flow is shown below:

Integration Builder - Sub-Flow Example

The JS Step, consoleLog simply prints some info to the console and also computes a response as follows:

console.log(trigger);

console.log(config);

console.log(config.parentFlowVariable);

done({value:trigger.args.inputVal*2});

We’ll look at the console for a sample execution later but for now, what’s important is the following:

  • We are printing the trigger which will contain arguments passed in from the parent flow
  • We are printing the config which will contain variables passed in from the parent flow AND any parent flow variables
  • We are accessing a variable, parentFlowVariable, that is NOT passed in from the parent flow as follows:
config.parentFlowVariable

Note that this is to show that the sub-flow has access to any parent flow variables whether they are passed in or not. This is not best practice since the sub-flow shouldn’t know anything about the parent flow scope.

  • We are accessing an argument, inputVal, passed in from the parent flow a follows:
trigger.args.inputVal
  • We are computing a response (doubling the inputVal) for the parent flow:
done({value:trigger.args.inputVal*2});

Use the Sub-flow

Let’s create a flow and use the Sub-flow. My simple test flow is shown below:

You can find the sub-flow step at the bottom of the step list when you add a step:

Integration Builder - Sub-Flow Example

The first thing we can look at is how we prepared to call the sub-flow in the prepareSubflow JS Script step:

done(
  {
    args:
    {
      inputVal:10,
      inputArray: [1,2,3,4,5],
      inputStr: "Hello World"
    },
    subFormulaConfigs:
    {
      var1: '11111',
      var2: '2222'
    }
  }
);

You can see we are creating an object with two properties: args and subFormulaConfigs. We construct our arguments in the args object and the variables in the subFormulaConfigs object.

The sub-flow step is shown below:

It has a step name, SubFlowStep and the ID of the sub-flow created above, 30810. It also contains the arguments and variables computed in the prepareSubflow JS Script step above it:

  • ${steps.prepareSubflow.args}
  • ${steps.prepareSubflow.subFormulaConfigs}

The last step in the test flow is a consoleLog JS Script step to print the results of the sub-flow, value:

console.log(steps.SubFlowStep.value);

View the Results

Let’s look at the execution log to see how arguments and variables were passed and results computed and accessed.

Here is the log for the prepareSubflow step.

You can see the arguments and variables being created.

Here is the log for the SubFlowStep step:

You can see 3 items in the console:

  • The trigger that contains the arguments:
{
  "args": {
    "inputVal": 10,
    "inputArray": [
      1,
      2,
      3,
      4,
      5
    ],
    "inputStr": "Hello World"
  }
}
  • The config which contains the variables passed in as well as parent flow variables:
{
  "parentFlowVariable": 33,
  "var1": "11111",
  "var2": "2222"
}
  • The parentFlowVariable value accessed directly:
33

We can also see the value that was computed and returned (20).

This same value is printed in the final parent flow step shown below:

Summary

In this blog post we looked at the mechanics of creating and using an Integration Builder Sub-flow step to help create cleaner, more maintainable flows.

Discover Axway’s Integration Builder scheduled flow example.