A rule consists of three components:

  • Expression: A conditional statement that is evaluated against each transaction to determine whether it satisfies the criteria of the rule.
  • Priority: If multiple rules match a transaction, the rule with the highest priority will be implemented first.
  • Destination Ledger: This is the name of the ledger into which the transaction will be categorized if the rule conditions are met. If the specified ledger name doesn’t exist in an instance’s chart of accounts, the system will disregard the rule.

Expressions

Expressions are written by using one or a combination of possible patterns:

  • The match(pattern, input) function, which compares a pattern, which can be text, numbers, booleans, or dates, with an attribute of the Transaction object as the input.
  • Direct comparison of the Transaction object using operators and literals.

The Transaction object

The entire Transaction object is accessed via the symbol t and references specific fields using ., for example, t.description or t.amount.

{
    {
      "amount": 100,
      "datetime": "2022-01-01T00:00:00Z",
      "description": "Shell Gas Bar 4124",
      "id": "t_9237232",
      "metadata": {
        // ...
      },
      "posted_status": "posted",
      "review_status": "reviewed"
    }
}

If metadata was added to the Transaction, you can reference it through t.metadata. See submitting transactions for more information on adding metadata to your transactions.

Operators and literals

Expressions may include the following operators and literals:

Using match()

Use match(pattern, input) to check if an attribute of the Transaction object, input, matches an arbitrary rule, pattern. The pattern must be a string and can contain regular expression syntax which we recommend to write complex rules.

You can learn more about regular expressions and their syntax here.

Examples

Payments to a specific vendor

A rule that checks if the Transaction’s description contains “Slack”, preceded by any number of any characters:

match(".*Slack", t.description)

will match

{
    "t": {
        "description": "Abc 7890Slack xYz"
        // ...
    }
}
Payments to a specific merchant over a given threshold amount

A rule that applies to any transaction where the Transaction description is exactly “Chevron” and the amount is more than $50:

match("Chevron", t.description) and t.amount > 50

will match

{
    "t": {
        "description": "Chevron",
        "amount": 60
        // ...
    }
}

but will not match

{
    "t": {
        "description": "abc Chevron", // false
        "amount": 60 // true
        // ...
    }
}

or

{
    "t": {
        "description": "Chevron", // true
        "amount": 40 // false
        // ...
    }
}
Transactions with certain metadata

A rule that looks for transactions with a counterparty attribute in the metadata set to “Sophie’s Contracting LLC”:

t.metadata.counterparty == "Sophie's Contracting LLC"

will match

{
    "t": {
        "metadata": {
            "counterparty": "Sophie's Contracting LLC"
        }
        // ...
    }
}

Relevant resources