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

Gen AI

Clay MCP in ChatGPT

Connect the Clay MCP to ChatGPT, sign in to your workspace, and see what you can build and run from a chat on your plan.

View article
Settings & admin

Best practices before a member leaves your workspace

Audit admin access, billing, connections, automated work, and sequencer senders before you remove a member from your workspace.

View article
Getting started

Enhanced matching

Enhanced matching is Clay's hashed email enrichment: it finds the personal email identifiers ad platforms recognize, so more of your audience matches when you sync it.

View article
Signals & triggers

Ad lead form triggers

Send LinkedIn and Meta lead generation submissions into a Clay workflow, so each new lead is qualified, routed, or written to Audiences automatically.

View article
Export

Credit refunds

Learn when Clay refunds Actions and Data Credits, and which actions refund when a provider returns no data.

View article
Enrich

Definitive Healthcare integration

Find US hospitals in Clay and enrich them with executives, physicians, networks, payor mix, technology, and financial metrics.

View article
Enrich

Reusing saved enrichment data

Keep the data your enrichments return so later runs can reuse it instead of paying for the same answer twice.

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