Skip to main content

If Else

Rather than using traditional if...else if...else statements in JavaScript, you can visually create conditional logic with this activity. This approach simplifies complex JavaScript logic by breaking it down into more manageable components.

If activity evaluates the incoming data based on a series of defined conditions and follows the appropriate branch:

  1. The If branch is executed if its condition evaluates to a truthy value.
  2. If the If branch condition is falsy, the workflow evaluates ElseIf branches sequentially. The first ElseIf branch with a truthy condition is executed.
  3. If none of the If or ElseIf conditions are met, the Else branch is executed.

Every branch has conditions that determine whether it should be executed.

Condition

A condition is composed of three essential components, each of which helps in defining the logic for evaluation:

  1. Field: This represents the data sourced from the workflow. It can refer to variables or results from other activities or payload. Examples include:

    • {{payload.name}}
    • {{api1.result.price}}
    • {{slack1.result.users}}
  2. Condition (Operator): This is the list of operators used to compare the field against the provided data. You will find the list of all the supported operators below.

  3. Data: This is the value against which the field is compared. The data can vary depending on the operator chosen:

    • In some cases, data is required for comparison (e.g., for operators like equals, greater than).
    • In other cases, data isn't required (e.g., is truthy, exists).

Operators

Operator
MeaningExample
less thanLess than comparison{{payload.age}} less than 18
greater thanGreater than comparison{{api1.result.price}} greater than 100
less than or equalLess than or equal to comparison{{slack1.result.users}} less than or equal 50
greater than or equalGreater than or equal to comparison{{fn1.result.score}} greater than or equal 75
equalEquality comparison (works with numbers and strings){{payload.age}} equal 18 or {{api1.result.status}} equal "success"
strictly equalStrict equality comparison (checks both value and type){{payload.age}} strictly equal 18 or {{slack1.result.channel}} strictly equal "general"
does not equalInequality comparison (works with numbers and strings){{payload.age}} does not equal 18 or {{fn1.result.status}} does not equal "failed"
strictly does not equalStrict inequality comparison (checks both value and type){{payload.age}} strictly does not equal 18 or {{freshsales1.result.lead}} strictly does not equal "new"
containsChecks if string contains another string{{payload.description}} contains "error"
does not containChecks if string does not contain another string{{api1.result.message}} does not contain "success"
exactly matchesExact match comparison (string comparison){{slack1.result.status}} exactly matches "completed"
does not exactly matchChecks if strings do not exactly match{{fn1.result.status}} does not exactly match "completed"
is inChecks if string is present in another string{{payload.role}} is in "admin, user, guest"
is not inChecks if string is not present in another string{{freshsales1.result.role}} is not in "admin, user, guest"
starts withChecks if string starts with another string{{payload.name}} starts with "John"
does not start withChecks if string does not start with another string{{api1.result.name}} does not start with "John"
ends withChecks if string ends with another string{{slack1.result.name}} ends with "Doe"
does not end withChecks if string does not end with another string{{fn1.result.name}} does not end with "Doe"
matches regexMatches string with a regular expression (JavaScript).
Build Regex from here
{{payload.email}} matches regex "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
does not match regexChecks if string does not match a regular expression (JavaScript).
Build Regex from here
{{api1.result.email}} does not match regex "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
afterChecks if a date is after another date{{payload.date}} after "2023-01-01T00:00:00Z"
beforeChecks if a date is before another date{{api1.result.date}} before "2023-01-01T00:00:00Z"
equalsChecks if two dates are equal{{slack1.result.date}} equals "2023-01-01T00:00:00Z"
is trueChecks if a value is exactly true (boolean){{payload.isActive}} is true
is falseChecks if a value is exactly false (boolean){{api1.result.isActive}} is false
existsChecks if the field exists (is not null or undefined){{payload.name}} exists
does not existChecks if the field does not exist (is null or undefined){{api1.result.name}} does not exist
is truthyChecks if the value is truthy (non-falsy value){{payload.value}} is truthy
is falsyChecks if the value is falsy (null, undefined, false, 0, NaN, ""){{api1.result.value}} is falsy
is array emptyChecks if the array is empty{{payload.items}} is array empty
is array not emptyChecks if the array is not empty{{api1.result.items}} is array not empty
length equalsChecks if the length of an array equals a specified Number{{slack1.result.items}} length equals 5
length greater thanChecks if the length of an array is greater than a specified Number{{fn1.result.items}} length greater than 5
length less thanChecks if the length of an array is less than a specified Number{{freshsales1.result.items}} length less than 5
is object emptyChecks if an object is empty (no keys){{payload.details}} is object empty
is object not emptyChecks if an object is not empty (has keys){{api1.result.details}} is object not empty
object contains keyChecks if an object contains a specified key{{slack1.result.details}} object contains key "name"
object does not contain keyChecks if an object does not contain a specified key{{fn1.result.details}} object does not contain key "name"
is type ofChecks if the value is of a specific type (e.g., string, Number, etc.){{payload.age}} is type of "number"
not type ofChecks if the value is not of a specific type (e.g., string, Number, etc.){{api1.result.age}} not type of "string"

Additional Features

  • Multiple ElseIf branches supported: You can define as many ElseIf conditions as needed, creating more complex branching logic.
  • Multiple conditions in any branch: Within the If or ElseIf branches, you can specify multiple conditions, which are connected using AND or OR logic to refine the evaluation.

Advanced Options

For more information on advanced settings, see the Advanced Options documentation.