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:
- The If branch is executed if its condition evaluates to a truthy value.
- If the If branch condition is falsy, the workflow evaluates ElseIf branches sequentially. The first ElseIf branch with a truthy condition is executed.
- 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:
-
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}}
-
Condition (Operator): This is the list of operators used to compare the field against the provided data.
-
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
Below are the supported operators and their meanings:
- less than → Less than comparison. Example:
{{payload.age}}less than 18 - greater than → Greater than comparison. Example:
{{api1.result.price}}greater than 100 - less than or equal → Less than or equal to comparison. Example:
{{slack1.result.users}}less than or equal 50 - greater than or equal → Greater than or equal to comparison. Example:
{{fn1.result.score}}greater than or equal 75 - equal → Equality comparison (works with numbers and strings). Example:
{{payload.age}}equal 18 or{{api1.result.status}}equal "success" - strictly equal → Strict equality comparison (checks both value and type). Example:
{{payload.age}}strictly equal 18 - does not equal → Inequality comparison. Example:
{{payload.age}}does not equal 18 - strictly does not equal → Strict inequality comparison (checks both value and type)
- contains → Checks if string contains another string. Example:
{{payload.description}}contains "error" - does not contain → Checks if string does not contain another string. Example:
{{api1.result.message}}does not contain "success" - exactly matches → Exact string match. Example:
{{slack1.result.status}}exactly matches "completed" - does not exactly match → Opposite of exactly matches
- is in → Checks if a string is present in another string. Example:
{{payload.role}}is in "admin, user, guest" - is not in → Opposite of is in
- starts with → Checks if string starts with another string. Example:
{{payload.name}}starts with "John" - does not start with → Opposite of starts with
- ends with → Checks if string ends with another string. Example:
{{slack1.result.name}}ends with "Doe" - does not end with → Opposite of ends with
- matches regex → Matches a regular expression. Example:
{{payload.email}}matches regex^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$ - does not match regex → Opposite of matches regex
- after → Checks if a date is after another date. Example:
{{payload.date}}after "2023-01-01T00:00:00Z" - before → Checks if a date is before another date
- equals → Checks if two dates are equal
- is true → Checks if value is exactly true (boolean)
- is false → Checks if value is exactly false (boolean)
- exists → Checks if field exists (not null or undefined)
- does not exist → Checks if field does not exist
- is truthy → Checks if value is truthy
- is falsy → Checks if value is falsy (null, undefined, false, 0, NaN, or empty string)
- is array empty → Checks if array is empty
- is array not empty → Checks if array is not empty
- length equals → Checks if array length equals specified number
- length greater than → Checks if array length is greater than specified number
- length less than → Checks if array length is less than specified number
- is object empty → Checks if an object has no keys
- is object not empty → Checks if an object has keys
- object contains key → Checks if an object contains a specified key
- object does not contain key → Opposite of object contains key
- is type of → Checks if value is of specific type (e.g., string, number)
- not type of → Opposite of is type of
Additional Features
- Multiple ElseIf branches supported: You can define as many ElseIf conditions as needed to create complex branching logic.
- Multiple conditions in a branch: Within If or ElseIf branches, multiple conditions can be combined using AND or OR logic to refine evaluations.