Condition
The Condition step determines the next step in the action by evaluating a JavaScript expression. Return true
to execute the if step, or false
to execute the else step.
return {{data.length}} > 0;
Variables
Built-in variables
The following built-in variables are available for the Condition step:
// result of the previous step
return {{data}};
// error response of the previous step
return {{error}};
// incoming action params, passed in by components,
// the Execution/Loop action steps or when calling the action from the code
return {{params}};
// the response of the request, if the Code step follows an HTTP API step
return {{res}};
While {{data}}
and {{error}}
are specific to a particular step, {{params}}
is available in all steps.
Using variables
// use `{{data.<key>}}` to access a specific key
return {{data.name}};
// to access the first element of the array
return {{data[0]}};
// to access the `name` key of the first element
return {{data[0].name}};
Optional chaining
If, at some point, the variable's value is null
or undefined
, an optional chaining operator ?.
can be used to access a specific key.
For example:
// if `data` is `null` or `undefined`, `name` will not produce an error
return {{data?.name}};
// if `data` is `null` or `undefined`, `name` will not produce an error
return {{data?.[0]?.name}};
Use case examples
Execute the true
step if the data
array has some items:
return {{data.length}} > 0;
Execute the true
step if the component's value is set:
return !!{{ui.input.value}};
Check user role:
return {{user.role}} === 'admin';
Check multiple user roles:
return ['admin', 'manager'].includes({{user.role}});
Check that at least one user role is present:
return ['admin', 'manager'].some(role => {{user.roles}}.includes(role));
Last updated
Was this helpful?