> For the complete documentation index, see [llms.txt](https://docs.charted.com/ap-automation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.charted.com/ap-automation/charted-configuration/invoice-ai/rules.md).

# Rules

This page covers writing a Rule, which tells Invoice AI **what to do with data once it has read it**. A Rule applies if-then logic: when a document meets your condition, Invoice AI takes your action.

To change how Invoice AI reads a value off the document, write a [Direction](https://docs.charted.com/ap-automation/charted-configuration/invoice-ai/ai-directions.md) instead. For how to choose between them, see [Choosing the right tool](https://docs.charted.com/ap-automation/charted-configuration/invoice-ai/ai-directions.md#choosing-the-right-tool).

Open **Charted > AP Automation > Settings**, then press **Rules** in the left navigation under Invoice Automation.

## What to use a Rule for

* Assigning a subsidiary based on the address an invoice arrived from, such as when each subsidiary has its own AP mailbox
* Assigning a vendor
* Routing invoices to a specific person
* Setting a header field to a fixed or conditional value

Write Rules for subsidiary assignment and routing before go-live, when your requirement is specific and defined and you cannot wait for learning to begin. Leave your other configuration until you are processing real invoices.

## How Invoice AI decides the vendor and subsidiary

Invoice AI identifies the vendor and the subsidiary while it scans, before anyone opens the document. Each follows a priority order, and Invoice AI stops at the first level that produces an answer. A Rule sits at the top of both.

### Vendor

<table><thead><tr><th width="100">Priority</th><th width="240">What Invoice AI checks</th><th>How it works</th></tr></thead><tbody><tr><td>1</td><td>Your Rules</td><td>Explicit if-then logic. Overrides everything below.</td></tr><tr><td>2</td><td>A purchase order (PO) match</td><td>If Invoice AI finds a purchase order number on the document and that purchase order exists in NetSuite, it takes the vendor from it.</td></tr><tr><td>3</td><td>Documents you have already processed</td><td>Invoice AI looks for earlier documents with the same vendor name and subsidiary, and takes the vendor from the bill created from the most recent one. It recalls a match you confirmed, rather than guessing from a similar name.</td></tr><tr><td>4</td><td>A direct name search</td><td>Invoice AI searches your NetSuite vendor records using the vendor name and subsidiary it read from the document.</td></tr></tbody></table>

### Subsidiary

This applies to OneWorld accounts. Invoice AI follows the same pattern with two extra fallbacks.

<table><thead><tr><th width="100">Priority</th><th width="240">What Invoice AI checks</th><th>How it works</th></tr></thead><tbody><tr><td>1</td><td>Your Rules</td><td>Logic you wrote</td></tr><tr><td>2</td><td>A purchase order match</td><td>Invoice AI takes the subsidiary from the matched purchase order.</td></tr><tr><td>3</td><td>Documents you have already processed</td><td>Invoice AI looks for earlier documents with the same bill-to name, and takes the subsidiary from the bill created from the most recent one.</td></tr><tr><td>4</td><td>The prior bill</td><td>If Invoice AI identified the vendor from your history, it carries the subsidiary across from that same bill.</td></tr><tr><td>5</td><td>The vendor's primary subsidiary</td><td>If the vendor came from a Rule or a name search, Invoice AI uses the primary subsidiary on your NetSuite vendor record.</td></tr><tr><td>6</td><td>Your Default Subsidiary setting</td><td>The last resort, set on the General Settings tab of Invoice AI Settings</td></tr></tbody></table>

Invoice AI leaves the field empty when it cannot determine a subsidiary. You set the Default Subsidiary on [Invoice AI settings](https://docs.charted.com/ap-automation/charted-configuration/invoice-ai/invoice-ai-settings.md).

### Using the priority orders

Work down from the top when a field resolves unexpectedly. Check whether a Rule governs the outcome, then whether a purchase order supplied it, then whether your history explains it.

This also explains why a new vendor's first document behaves differently from their tenth. Levels 1, 2 and 4 come from your configuration or from NetSuite. Level 3 builds as your team works, so until there is history, the lower levels govern entirely.

{% hint style="info" %}
Expect mismatches during testing, and again in your first weeks after go-live. Invoice AI does not carry learning from your sandbox into production, so it starts building history again. Matching improves once your team has processed and saved a few documents from a vendor.
{% endhint %}

If a vendor keeps resolving incorrectly, write a Rule. Invoice AI applies it every time and bypasses learning. See also [Why is Invoice AI picking the wrong vendor?](https://docs.charted.com/ap-automation/charted-faqs/invoice-ai/why-is-invoice-ai-picking-the-wrong-vendor.md)

## Conditions and actions

A Rule has two parts, and you must complete both.

| Part       | Commonly used                                                                                                          |
| ---------- | ---------------------------------------------------------------------------------------------------------------------- |
| Conditions | Email From, Email Subject, Email CC Addresses, Document Body Contains, Document File Name Contains, Transaction Vendor |
| Actions    | Assign Subsidiary, Assign Queue Owner, Assign Vendor, set a header field to a value                                    |

{% hint style="warning" %}
Complete both sections before you save. A Rule saved with one side incomplete can fire on every document, fire incorrectly, or do nothing at all.
{% endhint %}

## Writing a Rule

1. In the left navigation under Invoice Automation, press **Rules**.
2. Press **Open Rules**. The **Charted OCR Rule** list opens in a new tab.
3. Press **New Charted OCR Rule**.
4. Enter a descriptive **Rule Name**.
5. In the conditions section, choose the condition that identifies the documents you want to act on.
6. In the actions section, choose what Invoice AI should do when those conditions match.
7. Press **Save**.

Check both sections are complete before saving: "When receiving a document where all selected conditions apply" and "Take the following actions".

## Editing or deactivating a Rule

Open the **Charted OCR Rule** list as above and press **Edit** beside the Rule. Change it and press **Save**, or check **Inactive** and press **Save** to switch it off. An inactive Rule no longer appears in the list.

## Why a Rule does not fire

{% hint style="warning" %}
Reference list values by NetSuite internal identifier, not by display name. A Rule that sets a header-level list or record field needs the internal identifier. A Rule pointing at a display name will not work.
{% endhint %}

A Rule reaches header-level fields only. For a line-level field, write a [Direction](https://docs.charted.com/ap-automation/charted-configuration/invoice-ai/ai-directions.md) instead — in most cases a [custom field extraction](https://docs.charted.com/ap-automation/charted-configuration/invoice-ai/custom-field-extraction.md).

## Next

[Advanced settings](https://docs.charted.com/ap-automation/charted-configuration/invoice-ai/advanced-settings.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.charted.com/ap-automation/charted-configuration/invoice-ai/rules.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
