> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tesouro.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Trigger examples

> Explore scenarios to gain insights into how to customize the conditions for approval policies with practical situations, and adapt them to fit the distinctive needs and goals of your organization.

## Overview

On this page, we delve into a variety of real-world scenarios of [conditions for triggering approval policies](/finops/guides/accounts-payable/approvals/policies/index#approval-policy-structure). These scenarios are designed to help you understand how [approval policies](/finops/guides/accounts-payable/approvals/policies/index) can be automatically set to specific invoices and how to customize these conditions to address specific operational, compliance, and governance needs within your organization.

<Info>
  * The conditions mentioned on this page are designed using the
    [TesouroScript](/finops/guides/advanced/tesouroscript) and must be inserted into the `trigger`
    field. Check the [Evaluated string](/finops/guides/advanced/tesouroscript#evaluated-string)
    section for further information about the syntax. - The `"{event_name == "submitted_for_approval"}
      "` condition is mandatory in triggers. - The `if`, `then`, and `else` statements are not allowed
    in triggers. - When a payable has `enforce_approval_policy_id` set, the TesouroScript trigger
    conditions are ignored.
</Info>

## By invoice amount

Set an approval policy for all invoices worth more than 300 USD:

```json lines theme={null}
{
  "name": "Invoices worth more than 300 USD",
  "trigger": {
    "all": [
      "{event_name == 'submitted_for_approval'}",
      "{invoice.currency == 'USD'}",
      "{invoice.amount > 30000}"
    ]
  },
  "script": [
    ...
  ]
}
```

If you receive invoices in multiple currencies, you can convert the amount to some base currency to use the same threshold for all invoices:

```json expandable lines theme={null}
{
  "name": "Invoices worth more than 300 USD (after currency conversion)",
  "trigger": {
    "all": [
      "{event_name == 'submitted_for_approval'}",
      {
        "left_operand": {
          "call": "Currency.convert",
          "params": {
            "amount": "{invoice.amount}",
            "from_currency": "{invoice.currency}",
            "to_currency": "USD"
          }
        },
        "operator": ">",
        "right_operand": 30000
      }
    ]
  },
  "script": [
    ...
  ]
}
```

## With specific currencies

Set an approval policy for all invoices with specific currencies, in this case, USD and CAD:

```json lines theme={null}
{
  "name": "USD and CAD invoices",
  "trigger": {
    "all": [
      "{event_name == 'submitted_for_approval'}",
      "{invoice.currency in ['USD', 'CAD']}"
    ]
  },
  "script": [
    ...
  ]
}
```

## With specific tags

Set an approval policy for all invoices containing one of the specific tags:

```json expandable lines theme={null}
{
  "name": "Invoices with specific tags",
  "trigger": {
    "all": [
      "{event_name == 'submitted_for_approval'}",
      {
        "any": [
          "{'Marketing' in invoice.tags.name}",
          "{'Urgent' in invoice.tags.name}",
          "{'d566f374-463a-4a07-b252-2eb0200d62ce' in invoice.tags.id}",
          "{'398b2748-b255-46da-b8dc-a01219539ec9' in invoice.tags.id}"
        ]
      }
    ]
  },
  "script": [
    ...
  ]
}
```

## From a specific project

Set an approval policy for all invoices related to specific projects:

```json lines theme={null}
{
  "name": "Invoices from a specific project",
  "trigger": {
    "all": [
      "{event_name == 'submitted_for_approval'}",
      "{invoice.project_id == 'd566f374-463a-4a07-b252-2eb0200d62ce'}"
    ]
  },
  "script": [
    ...
  ]
}
```

## For specific counterparts

Set an approval policy for all invoices from a specific list of counterparts:

```json lines theme={null}
{
  "name": "Invoices from specific counterparts (vendors)",
  "trigger": {
    "all": [
      "{event_name == 'submitted_for_approval'}",
      "{invoice.counterpart_id in ['398b2748-b255-46da-b8dc-a01219539ec8', '4d0ff737-070b-427a-980c-c8ee7961577d']}"
    ]
  },
  "script": [
    ...
  ]
}
```

## For specific users

Set an approval policy for all invoices from a specific list of organization users:

```json lines theme={null}
{
  "name": "Invoices uploaded by specific organization users",
  "trigger": {
    "all": [
      "{event_name == 'submitted_for_approval'}",
      "{invoice.was_created_by_user_id in ['d566f374-463a-4a07-b252-2eb0200d62ce', '398b2748-b255-46da-b8dc-a01219539ec9']}"
    ]
  },
  "script": [
    ...
  ]
}
```

## By amount, currency, tags, AND specific counterpart

Set an approval policy for all invoices worth more than 1000 USD, from a specific counterpart AND with specific tags:

```json expandable lines theme={null}
{
  "name": "By amount, currency, tag, AND specific counterpart",
  "description": "Invoices worth more than 1000 USD, from a specific counterpart AND with specific tags",
  "trigger": {
    "all": [
      "{event_name == 'submitted_for_approval'}",
      "{invoice.amount > 100000}",
      "{invoice.currency == 'USD'}",
      "{invoice.counterpart_id == '398b2748-b255-46da-b8dc-a01219539ec8'}",
      "{'d566f374-463a-4a07-b252-2eb0200d62ce' in invoice.tags.id}",
      "{'398b2748-b255-46da-b8dc-a01219539ec9' in invoice.tags.id}"
    ]
  },
  "script": [
    ...
  ]
}
```

## By counterpart, plus amount OR specific tag

Set an approval policy for all invoices from a specific counterpart worth more than \$300 OR with a specific tag:

```json expandable lines theme={null}
{
  "name": "By counterpart, plus amount OR specific tag",
  "trigger": {
    "all": [
      "{event_name == 'submitted_for_approval'}",
      "{invoice.counterpart_id == '398b2748-b255-46da-b8dc-a01219539ec8'}",
      {
        "any": [
          "{invoice.amount > 30000}",
          "{'d566f374-463a-4a07-b252-2eb0200d62ce' in invoice.tags.id}"
        ]
      }
    ]
  },
  "script": [
    ...
  ]
}
```
