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 helpers 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.
Create a new workflow, using a manual trigger.
Add a Slack connector, and choose the "Channel Exists?" operation. Type a channel name that does exist for now:
Add a boolean condition connector to the workflow, and pass the "exists" property from Slack to the 1st Value property in the boolean condition.
Change the type of the "2nd Value" property to "boolean"
Ensure that the checkbox is checked. (This means that it is "true").
Note: 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.
Add a Slack connector to the "TRUE" branch, to send you a message indicating that the channel exists in Slack.
Click 'Run workflow now' - you should see a message appearing in Slack!
Add another Slack connector to the "FALSE" branch, to send you a message indicating the channel doesn't exist:
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.
Run the workflow again - you should see the message from the FALSE branch this time!