Build Flow Templates

Flow templates enable you to build a single template for a flow that you can reuse with different connectors and values. After you build a flow template, you can then create a flow instance where you replace the variables with actual connector instances and values. This approach helps you build efficient and reusable flows.

Build a Flow Template

Flow templates include a trigger that kicks off the flow, steps that execute as a result of the trigger, and variables to represent input required to run an instance of the flow. You can build flows that use triggers that kick off when something happens to a connector instance, you can schedule triggers, or you can manually kick off a trigger. See Triggers, Steps, and Variables for more information about each component.

As you build a flow, you also build a context consisting of triggers, variables, steps, and values created by steps. You can refer to that context in later steps in the flow. Consider each part as a building block that has a name and information that you can refer to. For example, in a flow that sends an email notification for a new contact, you build the body of the email in one step. In a later step, when you actually send the message, refer to the step where you built the body.

Icon

Use these steps to get started building a flow template. Consider using some of the example flow to get a deeper understanding of how to build a flow template.

Create a flow template in the UI

  1. Open the Flows page.
  2. Click Build New Flow Template.
  3. Click Build New Flow.
  4. Enter a name for your flow, and then click Create.
    Axway AMPLIFY provides you a list of triggers. For details about each trigger, see Triggers, Steps, and Variables.
  5. Select your trigger.

    Icon

    If you need to change a trigger in a flow template, you can delete it and start over. Deleting a trigger also deletes all the following steps, so do so with caution.

    • Choose Event for a flow triggered by an event configured on a connector instance.
    • Choose Connector Request for a flow triggered when a specific request is made to a connector instance.
    • Choose Scheduled for a flow to occur at a specific time or regular interval.
    • Chose Manual to trigger the flow with an API call to  POST /formulas/instances/:id/executions.
  6. Complete the trigger properties, which vary based on the selected trigger.
  7. Click Save.
    Axway AMPLIFY shows the first trigger node in the flow visualization.
  8. Add any variables that you will need to run the flow instance.
    1. Click Variables.
    2. Select the type of variable, and then enter a name.

      Takes note of the Flow Step Variable Name, which is how you will refer to the variable throughout the flow.

    3. Click Save.
  9. Add your first step. In the flow visualization, click .

  10. Select the type of step that you want to add.

  11. Complete the step properties, and then click Save. For details on each step, see Connector Instance Variable.

    Icon

    Click Add From Existing to find a step to copy.

    Axway AMPLIFY shows the first trigger node and the step that you just created in the flow visualization. The path from the trigger to the step defaults to On Success, but you can add failure steps later.

  12. To add another step, click the step, and then select one of the following:

    • Insert Above adds a new step prior to the current step with an On Success path connecting the two.
    • Add On Success adds a step for the flow to continue to if the current step succeeds.
    • Add On Failure adds a step for the flow to continue to if the current step fails.
  13. Continue adding steps until you complete the flow template.

  14. Add a description by clicking Edit. See Add a Description to a Flow Template.

  15. After you complete the flow, test it.

Icon

Axway AMPLIFY saves your flow template in the background as you add each component.

Build a Flow Template via API

You can build a flow with an API request to the POST /formulas endpoint. Your flow JSON includes the triggers, steps, and variables that make up your flow. The configuration object contains your variables, while the triggers and steps objects contain their relevant information. See the sample file below:

{  
  "name":"Flow Name",
  "description":"Flow Description.",
  "configuration":[  
    {  
      "name":"instanceName",
      "type":"elementInstance",
      "key":"instanceName"
    },
    {  
      "name":"instanceName2",
      "type":"elementInstance",
      "key":"instanceName2"
    }    {  
      "name":"valueName",
      "type":"value",
      "key":"valueName"
    }
  ],
  "triggers":[  
    {  
      "type":"event",
      "properties":{  
        "elementInstanceId":"${instanceName}"
      },
      "onSuccess":[  
        "step1"
      ]
    }
  ],
  "steps":[  
    {  
      "name":"step1",
      "type":"filter",
      "properties":{  
        "body":"done(trigger.event.eventType === 'UPDATED' && trigger.event.objectType === 'Contact');"
      },
      "onSuccess":[  
        "step2"
      ]
    },
    {  
      "name":"step2",
      "type":"script",
      "properties":{  
        "body":"done({\n  \"subject\": \"CRM Event Occurred\",\n  \"to\": \"recipient@cloud-elements.com\",\n  \"from\": \"sender@cloud-elements.com\",\n  \"message\": `${trigger.event.objectType} with ID ${trigger.event.objectId} was ${trigger.event.eventType}`\n});"
      },
      "onSuccess":[  
        "step3"
      ]
    },
    {  
      "name":"step3",
      "type":"elementRequest",
      "properties":{  
        "method":"POST",
        "elementInstanceId":"${instanceName2}",
        "api":"/messages",
        "body":"${steps.step2}"
      }
    }
  ]
}

Test Flow Templates

You can test a flow template as you build it. When you test a flow template, you can either use an existing flow instance or build a new flow instance.

Icon

If you plan to use the flow instance that you build while testing flows only for testing, consider appending the name test to it.

To test a flow template:

  1. At the top of the flow visualization, click Setup Test
  2. Click Select Instance.
  3. Either choose an existing flow instance (and skip down to the Select Trigger step) or click Add New Instance.
    1. Enter a name for the new flow instance.
    2. For each variable, click the variable and add a connector instance or enter a value.
    3. Click Create Instance.
    4. Select the instance that you just built.
  4. Click Select Trigger.
  5. Provide trigger information, depending on the type of trigger.

Create Variables

You can create two types of variables: Connector Instance variables — replaced by connector instances in the flow instance — and Value variables — replaced by values entered in the flow instance. When you create a variable, note the Flow Step Variable Name which is how you refer to the variable in the flow context. See Flow Variables for more about variables in the flow context.

To create a flow variable:

  1. Open the flow template. On the Flows page, hover over the flow card, and then click Open.
  2. Click Variables.
  3. Select the type of variable to create.
  4. Enter a name for the variable. You can include spaces, but we remove the spaces to create the Flow Step Variable Name (identified as key in the JSON), which is how you refer to the variable in the flow context.
  5. Click Save.

Edit and Delete Variables

You can edit the name of a variable or remove a variable from a flow template.

Icon

You cannot delete a flow variable if an instance of the flow exists.

To edit or delete a flow variable:

  1. Open the flow template. On the Flows page, hover over the flow card, and then click Open.
  2. Click Variables
  3. Click Edit Variable.
  4. Select the variable to edit or delete, and then:
    • Edit the name, and then click Save. Or,
    • Click Delete.

Review and Replay Executions

You can troubleshoot flow by reviewing executions. 

The executions appear in three columns from left to right:

  • Flow Executions — the list of executions of the selected flow template. We identify failed executions in red.
  • Steps —The steps in the flow and an icon showing their success or failure .
  • Execution Values —the request and response details associated with the selected step. 
Icon

To review executions, you must have a flow instance. Otherwise, the Executions button is unavailable.

To review executions:

  1. On the Flows page, hover over the flow card, and then click Open.
  2. Click Executions.
  3. Click the execution to review.
  4. Click the step to review.

To replay executions:

  1. On the Flows page, hover over the flow card, and then click Open.
  2. Enable debugging by clicking the Debugging toggle.
  3. Click Select Instance.
  4. Either select an existing flow instance by clicking its corresponding plus sign button, or click the Create Flow Instance button to create a new instance and define its variables.
  5. After selecting an instance, click Run.

    As the execution runs, you can click the individual steps to see the step's execution value.

Copy a Flow Template

You can build a flow template based on an existing template or from an Axway AMPLIFY sample flow, resulting in a copy of the template.

To build a copy of a flow template:

  1. Click Flows, and then on the Flows page, click Build New Flow.
  2. Click Build From Existing Flow.

    • To use one of your existing flow templates, select the template.
    • To use an Axway AMPLIFY flow template, click Sample Flows, and then select the flow.
  3. Enter a name for your flow, and then click Create.

Import and Export Flow Templates

You can export a flow template as a JSON file and import other templates from their JSON source file.

To import a flow template:

  1. Click Flows, and then on the Flows page, click Build New Flow.
  2. Click Import.
  3. Select the JSON file to import.
  4. Optionally rename the file, and then click Create.

To export a flow:

  1. Navigate to the Flows page.
  2. Hover over the connector card, and then click Export.
  3. Save the file.

Parallel Executions

To help flow instances execute as efficiently as possible, they take advantage of multithreaded executions. That is, multiple executions of the same flow instance can make requests at the same time. Some API providers prevent multiple requests from the same account at the same time. If this happens, you can change a flow template or an individual flow instance to execute one step at a time. This makes the flow less efficient and results in an increase in the execution time.

To change the flow from the default multithreaded execution to single-threaded:

  1. Open the flow template. On the Flows page, hover over the flow card, and then click Open.
  2. Click Edit.
  3. Click Show Advanced.
  4. Switch Single-Threaded Execution on.
  5. Click Save.

Alternatively, in the flow template or flow instance JSON, update singleThreaded to true:

{
"singleThreaded": true
}

Rename a Flow Template

To rename a flow template:

  1. Open the flow template. On the Flows page, hover over the flow card, and then click Open.
  2. Click Edit.
  3. Rename the flow template.
  4. Click Save.

Add a Description to a Flow Template

Descriptions provide more information about a flow template. Use the information to describe the flow template use case and anything another user might need when creating a flow instance.

To add a description to a flow template:

  1. Open the flow template. On the Flows page, hover over the flow card, and then click Open.
  2. Click Edit.
  3. Describe the flow template in Description.
  4. Click Save.

Delete a Flow Template

You can delete a flow template if the template has no instances associated with it. If the flow template includes instances, delete those first.

To delete a flow template:

  1. Navigate to the Flows page.
  2. Hover over the Flow Template card, and then click Delete.
  3. Confirm the deletion.

Deactivate a Flow Template

You can deactivate a flow template to prevent any executions of flow instances of the template.

Icon

You can also deactivate a specific flow instance. See Deactivate a Flow Instance.

To deactivate a flow:

  1. Open the flow template. From the Flows page, hover over the flow template card, and then click Open.
  2. Click Edit.
  3. Switch the Active slider off.
  4. Click Save.

Access Flow Information

Each flow template and flow instance exposes information about itself through the info object.

{
  "info":{
   "formulaId":"123",
   "formulaName":"name",
   "formulaInstanceId":"123",
   "formulaInstanceName":"name",
   "formulaExecutionId":"1234"
  }
}

Flow information contributes to the flow context. You can access the information with info.property, such as info.formulaInstanceId or info.formulaName.

Related Links