# Context

A context limits where entities, attributes, or specific properties are considered when fulfillmenttools executes business logic.

The following entities support contexts:

* Listings ([sales prices](https://docs.fulfillmenttools.com/documentation/getting-started/facilities/prices#sales-price), [out of stock behavior](https://docs.fulfillmenttools.com/documentation/by-pillar/global-inventory-hub/listing#out-of-stock-behaviour))
* [Facility discounts](https://docs.fulfillmenttools.com/documentation/getting-started/facilities/facility-discounts)
* [Facility connections](https://docs.fulfillmenttools.com/documentation/by-pillar/advanced-order-routing/complex-routing-with-combinatorics/network-model/facility-connection)
* [Roles](https://fulfillmenttools.github.io/fulfillmenttools-api-reference-ui/#get-/api/roles)

These entities contain a `context` field. The system evaluates the context at runtime to determine if the object applies to the current use case. If no context is defined, the system sets no limitations.

The structure of the `context` is as follows:

```json
{
    ...
    "context": [
        {
            "type": "FACILITY",
            "operator": "NOT",     // optional, not available in every entity
            "values": [
                "string"
            ]
        },
        ...
    ]
}
```

* Entries in the `context` array are joined with a logical `AND`.
* Items in the `values` array are joined with a logical `OR`.
* Each entity supports different context types, such as `CATEGORY`, `FACILITY_ID`, and `FACILITY_GROUP`.
* The `operator` field is optional, and the only supported value is `NOT`. Support for this field varies by entity.

### Example <a href="#example" id="example"></a>

This example shows how to create a discount that applies only to certain facility groups and excludes a specific article category.

Adding a `context` to the discount defines the conditions under which the system considers it when routing an order.

See the [facility discounts article](https://docs.fulfillmenttools.com/documentation/getting-started/facilities/facility-discounts) for more information related to discounts.

```json
{
    // discount entity
    ...
    "context": [
        {
            "type": "FACILITY_GROUP",
            "values": [
                "uuid-facility-group1",
                "uuid-facility-group2"
            ]
        },
        {
            "type": "CATEGORY",
            "operator": "NOT",
            "values": [
                "uuid-category1"
            ]
        }
    ]
}
```

In this example, the system applies the discount when:

* the facility is in facility group `uuid-facility-group1` **or** `uuid-facility-group2`

**and**

* the article category is **not** `uuid-category1`.

<br>
