Skip to content

If Condition ​

The If Condition block checks one or more rules and then picks a path: Success when the rules pass, Failure when they don't. Think of it as "if this, do that, otherwise do something else".

When to use it ​

  • Check something before you continue: is the user an admin, is the total above 100, is a field missing?
  • Give two different answers: return data when it exists, return a 404 when it doesn't.
  • Don't use it to pick between many options. Use Switch instead of a chain of Ifs.
  • Don't use it to check whether a database row exists. DB Row Exists does that in one step.

Inputs ​

FieldRequiredDefaultWhat it does
ConditionsNononeThe list of rules to check. Each rule has a left value, an operator and a right value.

Each rule has:

PartWhat it does
Left value / Right valueWhat to compare. Type a plain value like 100, or turn on JS to compute it, for example return input.total;.
Operator=, !=, >, >=, <, <=, Is Empty/Null, Is Not Empty/Null, or JS.
AND / ORHow this rule joins the rules before it.
GroupBrackets. The rules inside a group are checked together first.
  • Is Empty/Null and Is Not Empty/Null only use the left value. Empty means null, undefined, "", or an object or list with nothing in it.
  • JS lets you write the whole check yourself. Return true or false, for example return input.items.length > 0;. The previous block's output is available as input.

Outputs ​

The If Condition block does not change your data. Whatever it received is passed to the path that runs.

HandleWhen it is used
Success (right)The conditions are true.
Failure (right)The conditions are false.

Connect one block to each handle. A path you leave empty simply ends the flow there.

Example ​

Reject small orders. The previous block output { "total": 40 }.

Left valueOperatorRight value
JS: return input.total;>=50
  • total is 40, so the check is false and the flow goes to Failure. Connect a Response with code 400 there.
  • With total at 80 it goes to Success, and the next block receives { "total": 80 } unchanged.

How it behaves ​

  • Left to right, no precedence. a OR b AND c is read as (a OR b) AND c. Use a group when you need a different order.
  • No rules means true. With an empty list the flow always takes Success. An empty group is ignored.
  • Loose equality. = does not care about type, so the text "5" equals the number 5. Use JS with === when the type matters.
  • Stops early. Once the answer is clear, the remaining rules are skipped, so a rule that would throw is never run.
  • Errors. If a JS rule throws an error, the block fails and the Error Handler runs. It does not fall to Failure.
  • Failure is not an error. Taking the Failure path is a normal result, and the Error Handler does not run.
  • Saving the result. The block has no output of its own, so it has no "Save output to variable" option.

Released under the Apache License 2.0. Enterprise features are under the Fluxify Enterprise Edition License.