# Conditions

Conditions are used to compare values at runtime and add dynamic behavior to your apps. They are configured in the same way as [filters](/reference/platform-concepts/filters.md), but a condition will always return a true or false value. Conditions can be implemented when designing the [UI](/reference/apps/ui.md) (for example to set the **Visibility** property of a component), or building logic in [actions](/reference/actions.md) (for example in an [If action node](/library/action-nodes/if.md)).

To build conditions, you should also be familiar with [operators](/reference/platform-concepts/operators.md).

## Condition editor

Conditions are constructed using the condition editor. The most basic condition is a single expression made up of a *left operand*, an *operator*, and a *right operand*.

In the example below, the left operand is `Ticket.Status`, the operator is `Equals` and the right operand is `New`. The condition is evaluated at runtime and if the status of the ticket is new, the condition will return true.

<figure><img src="/files/GfRSgRzNVTpTodgtas8L" alt=""><figcaption><p>A basic condition with one expression</p></figcaption></figure>

A condition can also consist of multiple expressions. When you add an additional expression the new expression is compared to the previous expression with an **AND** operator. This means that *both* expressions must equate to true for the condition to return true. You can click the operator to toggle to **OR** and in that case, if *either* expression equates to true the condition will return true.

In the example below, the ticket status must be new *and* the description must contain a value (not empty or null) for the condition to return true.

<figure><img src="/files/yxtTXr9gXD36MeGWZehK" alt=""><figcaption><p>A condition with multiple expressions.</p></figcaption></figure>

Expressions can be combined within *groups*, and the result of the expressions within a group can be compared.

In the example below, the ticket status must be new and the description must contain a value (not empty or null) *or* the ticket must have been created prior to the start of the 2022. If either of these equate to true the condition will return true.

<figure><img src="/files/QNkzdcL1qU7dkIIDz7Fv" alt=""><figcaption><p>A condition with a group of expressions</p></figcaption></figure>

You can add a comment to a condition, and it can be useful to describe how a condition works when it contains many expressions.

<figure><img src="/files/UT13x5jRrmYYoPH0HDZB" alt=""><figcaption><p>A condition with a comment</p></figcaption></figure>

### Cardinalities of left and right side operands

The right operand may be a single value/object or a list of values/objects, whereas **the left operand may only be a single value or object,** except in the case where the left operand is a property with [Cardinality Many](/reference/data-model/object-class-properties.md#general-properties) (see example 5)**.**&#x20;

Here are some example setups of valid conditions, given the following data sources:

* `Person` (Cardinality *One*)
  * With a property `Department` (with cardinality One)
  * With a property `Tags` (with cardinality Many)
* `Departments` (Cardinality *Many*)
* `Tags` (Cardinality Many)

#### Example 1

<figure><img src="/files/rkjpEkYJz7bVjvXDKNA8" alt=""><figcaption><p>Conditions example with Single cardinality on both sides</p></figcaption></figure>

In the above example, the left operand is a single value. Since the `EQUALS`-operator is used, the right operand must be a single value. **The right operand is treated as a single value** if the `Departments` Data Source has a single [selected object](/reference/platform-concepts/objects.md#object-selection), or if the Departments Data Source has a [context object](/reference/platform-concepts/objects.md#object-in-context) (i.e. this condition is placed inside an iterator, such as inside a Foreach action node, looping the Departments Data Source).

#### Example 2

<figure><img src="/files/wQersIgHb6JgaLCEDTrD" alt=""><figcaption><p>Conditions example with Single cardinality on both sides</p></figcaption></figure>

This example is similar to example 1, but **the right side is a single property** itself. App Variables is in fact a single cardinality Data Source, and we've added a variable `Selected Department` to it.

#### Example 3

<figure><img src="/files/ZPmu6ErTLNM0iJo8KdA6" alt=""><figcaption></figcaption></figure>

In the above example, the left operand is a single value, similar to the previous examples. However, since the operator `EXISTS IN` is used, **the right side is multiple values**. In this case, the right side is a list of the IDs of the selected object in the `Departments` Data Source.

#### Example 4

<figure><img src="/files/OJCpSSN3cmY6E64Rp3Wm" alt=""><figcaption></figcaption></figure>

In this example, the left operand is still a single value. However, since the Departments Data Source has cardinality many, the above expression is only valid if the `Departments` Data Source has a single [selected object](/reference/platform-concepts/objects.md#object-selection), or if the Departments Data Source has a [context object](/reference/platform-concepts/objects.md#object-in-context) (i.e. this condition is placed inside an iterator, such as inside a Foreach action node, looping the Departments Data Source).

#### Example 5

<figure><img src="/files/c6BHh3gppVGNH2kj2t7Q" alt=""><figcaption></figcaption></figure>

In this example, we have a condition towards the multi-reference property `Person.Tags`. You may read more about multi-references [here](/how-to/data-modeling/many-to-many-relationships.md) if you are new to the concept, but in general, it is just a list of IDs (referencing 0 to many `Tags` in this example).

In the above condition, we check if the `Person.Tags` list contains some of the selected objects in the `Tags` data source.

You may read more about these multi-reference operators (Has All Of, Has Some Of, Has None Of) [here](/reference/platform-concepts/operators.md#logical-operators).

## Advanced conditions

In some cases, it may not be possible to create the condition you need in the condition editor. If so, you can instead write a function that returns either `true` or `false`. See [Advanced functions](/reference/platform-concepts/functions.md#advanced-functions) for examples of advanced conditions.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.appfarm.io/reference/platform-concepts/conditions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
