Conditional logic is a powerful feature of the tray.io workflow builder. It enables you to build intelligent workflows that only run steps under certain conditions. For example you might want to:
- Only sync Intercom users to Salesforce if they match a particular segment
- Send a message to a different Slack channel based on a form's input
Tray has two key connectors that help you do this: the "boolean condition", and the "branch" connector. Most of the time, you'll want to use the boolean condition.
Setting up conditional logic using the boolean condition
Here's how to set up a workflow that checks to see if a Slack channel exists or not, and then send a different message based on the result.
Step 1. Create a new workflow, using a manual trigger as the trigger for the workflow.
Step 2. Add a Slack connector, and choose the "Channel Exists?" operation. Type a channel name that does exist for now.
Step 3. Add a boolean condition connector to the workflow, and pass the "exists" property from Slack to the "1st Value" property in the boolean condition.
Step 4. Change the type of the "2nd Value" property to "boolean", and then ensure that the checkbox is checked. (This means that it is "true").
Tip: we've changed the type of the "2nd Value" to a "boolean" type because the type of the "exists" property coming from Slack is also a boolean.
Step 5. Add a Slack connector to the "TRUE" branch, to send you a message indicating that the channel exists in Slack.
Step 6. Run the workflow - you should see a message appearing in Slack!
Step 7. Add another Slack connector to the "FALSE" branch, to send you a message indicating the channel doesn't exist.
Step 8. Change the channel name in the first Slack step you added (the one to check if the channel exists) to a channel that doesn't exist.
Step 9. Run the workflow again - you should see the message from the FALSE branch this time!