Amplify Integration Builder Multi Trigger Flow

Amplify Integration Builder Multi Trigger Flow

While you can easily change a flow’s trigger type, say, from manual to schedule, flows can only have a single trigger type active at a time, so how can we design a flow that can be triggered by multiple trigger types?

Why would you want to do this? Well, you may have a flow that runs on a schedule and checks an application for new data. However, you may want to periodically trigger this flow manually to not have to wait for the next scheduled run.

One way to solve this problem is to have a single main, manual triggered flow and then use a platform API call to trigger it from multiple other calling flows, each with a different trigger type as depicted below:

Let’s describe how to set this up with a simple example. In this example, we’ll create a single manual triggered flow that would contain a majority of the logic and then trigger it manually from two calling flows, one, a schedule triggered flow, and the other, a manually triggered flow. We’ll also describe how to pass on data to the main flow in case the business logic needs to change depending on which calling flow triggered it.

Main Flow

* Create a new manual triggered flow and add a JS Script Step that console logs the trigger. I called mine “MultiTrigger Main Flow.”

* Create an instance of this flow, and note the instance ID as we’ll need this in order to trigger this flow from the calling flows using the Integration Builder Platform API call:

POST /formulas/instances/{instanceId}/executions

* Check that you can trigger the flow from the Platform API docs and check the trigger

* The flow is shown below:

Calling Flow 1

* Create a new manual triggered calling flow and add a string variable to store the main flow instance Id from above in order to trigger it. It should be noted that by default all new flows are manual. I called my flow “MultiTrigger Calling Flow 1 – Manual” and I called the instance variable “mainFlowInstanceId.”

* Add a JS Script Step to the trigger called “prepareTriggerMainFlow” with the following contents:

let body = {
  parentTriggerType: 'manual'
};

done({body});

* You can add any other parameters to the body object. These will be passed to the main flow

* Add a Platform API Request step to the trigger and populate as follows:

* The flow is shown below:

* Create an instance and populate the main flow instance Id from above and trigger it. You should see that it triggers your main flow:

* Note the args passed into the main flow

Calling Flow 2

* Create a new schedule triggered calling flow and add a string variable to store the main flow instance Id from above in order to trigger it. I called my flow “MultiTrigger Calling Flow 2 – Schedule” and I called the instance variable “mainFlowInstanceId” as above. You can change the trigger type from the default “manual” to “scheduled” by clicking on the trigger step and clicking “ADD TRIGGER” and then “Add Schedule Trigger” and selecting the desired schedule. I picked 1 minute.

* Add a JS Script Step to the trigger called “prepareTriggerMainFlow” with the following contents:

let body = {
  parentTriggerType: 'schedule'
};

done({body});

* You can add any other parameters to the body object. These will be passed to the main flow

* Add a Platform API Request step to the trigger and populate as follows:

* The flow is shown below:

* Create an instance and populate the main flow instance Id from above and trigger it. You should see that it triggers your main flow:

* Note the args passed in to the main flow

Summary

In this blog post, we showed one way to have a flow triggered by multiple trigger types. We accomplished this by creating the main flow that is manually triggered and triggering it from multiple calling flows, each with a different trigger type (manual and schedule).

The calling flows trigger the main flow using the Integration Builder Platform API call POST /formulas/instances/{instanceId}/executions with the instance Id of the main flow. The calling flows can pass data in the body of the POST, where it can subsequently be used in the main flow to alter its functionality.

Discover the three flows that you can download from here.

Learn more about Amplify Integration Builder Connector Instance Variables.

Previous articleXignite offers real-time market data for fintechs with Amplify Streams
Next articleNOV Inc. creates new value to deliver secure business services around the clock with Axway
Principal Presales Architect II – Leor Brenman has over 12 years’ experience in Enterprise Software and more than 30 years working in the tech industry for companies like Vaultus, Antenna, Appcelerator and Axway. He has a strong technology background and specializes in mobile, API, integration and enterprise applications. Leor has a BS and MS in Electrical Engineering from Rutgers University in NJ, USA.

LEAVE A REPLY

Please enter your comment!
Please enter your name here