Skip to main content

Branch Component

Choose which step to execute next based on a condition or value

Component key: branch

Description#

The branch component allows you to add branching logic to your integration. Think of branches like if/then or switch/case programming statements. Your integration can follow one branch or another depending on the values of some config variables or results from previous steps.

For example, if your customers have different data repositories (like Amazon S3, Azure Files, or Dropbox) that they would like integrations to write data to, you can use the Branch On Value action to execute AWS, Azure or Dropbox actions based on a config variable that is set for that customer.

You can also use the Branch On Expression action to follow different branches of execution based on complex comparisons and expressions. This is explained in more detail below.

Actions#

Branch on Expression#

Choose which step to execute next based on a condition | key: branchOnExpression

InputKeyNotes

Condition

conditional
/ Required
conditionsThe set of conditions to satisfy in order to branch.

The branch on expression action allows you to create logical branches within your integration based on comparisons of config variables, results from previous steps, or static values.

The full list of comparison functions you can use is available on our Building Integrations article.

Multiple expressions can be grouped together with And or Or clauses, which execute like programming and and or clauses. Take, for example, this programming expression:

if ((foo > 500 and bar <= 20) or ("b" in ["a","b","c"]))

The same logic can be represented with a group of conditionals:

Output Example Payload#

{  "data": null,  "branch": "Example Branch"}

Branch on Value#

Choose which step to execute next based on a value. | key: branchOnValue

InputKeyNotes

Branch Value Mapping

string
/ Required
branchValueMappingsThe branches that are associated with an expected value.

Input Value

string
/ Required
inputValueThe value used for routing to a branch. This should reference a config variable or output from a previous step.

The branch on value action allows you to branch into one of many paths of an integration based on an input and branch mapping. Think of it like a switch/case or if/elseif/else statement.

For example, if you have a config variable that could be set to "sms", "email" or "slack" based on how your customer would like to receive notifications, you can create branches for SMS, email, and Slack:

This setup would be equivalent to some pseudocode reading:

if required_config_vars.notification_preference == "sms":  send_an_sms()else if required_config_vars.notification_preference == "email":  send_an_email()else:  send_a_slack_message()
// or
switch(required_config_vars.notification_preference) {  case "sms":    send_an_sms()    break  case "email":    send_an_email()    break  default:    send_a_slack_message()}

An "else" branch is generated in the case that the input value does not match any of the values in your branch value mapping. In the example above, if the notification preference config variable is not equal to "sms" or "email", it's assumed that it must be equal to "slack", and the "Slack" branch is executed.

Output Example Payload#

{  "data": null,  "branch": "Example Branch"}

Select Executed Step Result#

Given a collection of step results, returns the results of whichever step was executed and returned a result. | key: selectExecutedStepResult

InputKeyNotes

Step Result

data
/ Required
stepResultsThe set of step results to consider when selecting a result from an executed step.

Regardless of which branch is followed, branches always converge to a single point. Once a branch has executed, the integration will continue with the next step listed below the branch convergence.

This presents a problem: how do steps below the convergence reference steps in branches that may or may not have executed (depending on which branch was followed)? In your integration you may want to say "if branch foo was executed, get the results from step A, and if branch bar was executed, get the results instead from step B." Prismatic provides this action to handle that scenario.

Imagine that you have two branches - one for incoming invoices, and one for outgoing invoices, with different logic contained in each. Regardless of which branch was executed, you'd like to insert the resulting data into an ERP. You can leverage this action to say "get me the incoming or outgoing invoice - whichever one was executed."

This action iterates over the list of step results that you specify, and returns the first one that has a non-null value (which indicates that it ran).

Within the component configuration drawer, select the step(s) whose results you would like, and this step will yield the result of whichever one was executed.

Output Example Payload#

{  "data": "Example"}