All docs
/
Getting started
/
Conditional statements

Conditional statements

Control the logic of your workflow

Overview

Conditional statements overview

Conditional statements in Clay help you control the flow of logic of your workflow, allowing you to perform different actions based on conditions. For example, if Company Size > 100, the output will be true.

In Clay, you can use conditional statements in:

  • Conditional runs: Run a certain enrichment based on certain criteria.
  • AI formulas: Transform data, like scoring leads or qualifying opportunities.
  • Conditional Snippets: Embed conditional logic to send outbound messages based on contact criteria.
  • Waterfalls: Maximizing coverage with multiple providers.

Conditional statement structure

Conditional statements have the following structure:

  1. IF (Condition) – Executes a command when the condition is true.
  2. ELSE IF (secondCondition) – Executes a command if the second condition is true (optional).
  3. ELSE – Executes a command when none of the above conditions are true.

Walkthrough

IF Condition

(command to execute if condition is true)

ELSE IF secondCondition

(command to execute if secondCondition is true)

ELSE

(command to execute if no conditions are true)

Best practices

Testing

Prevent unexpected errors with edge cases or missing data.

Examples

  • Empty fields: IF({{company_size}} > 100) THEN "Qualified" ELSE "Not Qualified" , Ensure blank company_size defaults to "Not Qualified".
  • Boundary values: Test company_size = 50 in IF({{company_size}} >= 50) THEN "Medium" ELSE "Small" to avoid misclassification.
  • Unexpected formats: Handle company_size = "unknown" by defaulting to "Not Qualified".

Error handling

Handle missing or invalid data properly.

Examples:

  • Missing fields: In IF({{company_size}} AND {{location}}) THEN "Valid" ELSE "Invalid", return "Invalid" if fields are missing.
  • Clear errors: Use IF({{email}} == "") THEN "Error: Missing Email" ELSE "Valid Email" to flag missing inputs.

Parentheses for clarity

Use parentheses to group conditions clearly, especially when combining multiple logical operators (AND, OR, NOT).

Examples:

  • Unclear: {{size}} > 100 AND {{location}} == "US" OR {{revenue}} > 1M could qualify the wrong leads.
  • Clear: (size > 100 AND location == "US") OR revenue > 1M ensures correct grouping.

Use cases: Lead qualification, CRM updates, or email campaigns where errors could disqualify valid leads or waste resources.

Example conditional statements within Clay

Example #1: Basic email validation

Validate email formats to flag personal email addresses.

Formula

IF (person.email contains @gmail.com OR @yahoo.com)return "Invalid email format"

ELSEreturn "Valid email format"

Test cases

Example #2: Message snippets based on company size

Serve different message snippets based on the company’s size.

Formula

IF (company.size > 500)

return enterprise_message_snippet

ELSE IF (company.size > 50)

return midmarket_message_snippet

ELSE

return small_message_snippet

Test cases

  • Input: company.size = 750Result: enterprise_message_snippet
  • Input: company.size = 100Result: midmarket_message_snippet
  • Input: company.size = 25Result: small_message_snippet
  • Input: company.size = 0Result: small_message_snippetNote: Since this input doesn't satisfy any of the conditions, the final else statement is returned, but we should add some input validation here.

Example #3: Regional discounts based on geography

Apply different discount rates based on the region.

Formula

IF (region == "US")

return "10% Discount"

ELSE IF (region == "EMEA")

return "15% Discount"

ELSE

return "No Discount Available”

Test cases

  • Input: region = "US"Result: 10% Discount
  • Input: region = "EMEA"Result: 15% Discount
  • Input: region = "APAC"Result: No Discount Available

Explore other docs

Find

Guide: Finding companies and people in Clay

Best practices to Clay's company and people search features.

View article
Find

ContactLevel integration

Enrich contacts in Clay with SHA-256 hashed personal email addresses for use in high-match ad audiences.

View article
Enrich

Google BigQuery integration

Import records from BigQuery into Clay using SQL queries, and send enriched data back by inserting, looking up, updating, or upserting rows in your BigQuery tables.

View article
Find

Enigma integration

View article
Find

Vector integration

Find hashed emails with Vector.

View article
Enrich

CB Insights

Enrich company records with funding history, valuations, revenue ranges, industry classifications, and more.

View article
Getting started

Functions

Functions let you convert any enrichment sequence into a reusable workflow. Once created, you can use it across any table — and any updates you make to the function automatically apply everywhere it's used.

View article

Other popular resources

Experts

Find a Clay Expert

Explore our network of Clay experts and agencies.

View experts
Community

Join our slack community

Find help in our slack community, and support channels.

Go to slack
Cohorts

Join a cohort, learn Clay fast!

The faster way to master Clay. Sign in if you're enrolled in a cohort (current or past) or apply!

Learn more about cohorts
Talents

Hire GTME Talent

Find and connect with GTM talent who've demonstrated expertise in building advanced workflows

Explore GTME talents