Site iconAxway Blog

Axway Integration Builder – Variable Persistence

Axway Integration Builder – Variable Persistence

Flow Value variables are defined in the flow and set in the instance. Each time the flow executes the value is reset to the value in the instance. What if you’d like to modify the variable and have the value persist between flow executions? Why would I even want to do this?

One reason you may want to have a variable persist between flows is if the flow needs to query a data source to see what changed since the last execution. In this case you will need to store the time stamp of the last execution. While you could store the variable in an external database, with Axway’s Integration Builder there is no need to do this. This blog post will describe how to use Platform API requests to store a value variable between flow executions.

Here are the basic steps:

Let’s dive in.

Create a Value Variable

Read the Value Variable

Update the Variable

Retrieve the Formula Instance Metadata

let url = `/formulas/${info.formulaId}/instances/${info.formulaInstanceId}`;

done({url: url});

Note that my step is called prepareGetFormulaInstanceMetadata.

Note that my step is called getFormulaInstanceMetaData.

Modify the Value Variable

We will do this in the same step as updating the formula instance below.

Update the Formula Instance

Now we can update the formula instance with our revised variable value so that it can be accessed during the next execution of the flow.

let formulaInstance = steps.getFormulaInstanceMetaData.response.body;

formulaInstance.configuration.lastExecutionTime = Date.now();

done({body:formulaInstance});

Note that we are setting the value variable lastExecutionTime to the current time.

Note that my step is called prepareUpdateLastExecutionTime.

Note that we are using the url calculated earlier since it is the same

Note that my step is called updateLastTimeStamp.

The entire flow should look as follows:

Test Flow

Let’s test our flow by creating an instance setting lastExecutionTime to 0

After a few minutes you should see the flow has executed a few times as follows:

If you look at the consoleLog step you will see time stamps similar to below:

The first 0 is the variable value that was set in the instance. The remaining are time stamps for each flow execution.

You can check this web site to convert the timestamps to a human readable time and you will see that there is roughly 1 minute between each timestamp. This is the cron interval we set when creating the flow.

Summary

In this blog post we saw how it is possible to persist data between flow executions, which would be useful for applications that need to query data that has changed since last check as well as other use cases.

You can find my test flow here.

Exit mobile version