Skip to content

Commit

Permalink
add docs for rule action templating experimental feature (#632)
Browse files Browse the repository at this point in the history
Closes #480

Feedback issue for the reference
actualbudget/actual#3606

This is a starting point for a more fleshed out version, adding examples
in the future would be good
  • Loading branch information
matt-fidd authored Feb 13, 2025
1 parent 55e41fb commit cd1b5f1
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs-sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ const sidebars = {
'experimental/monthly-cleanup',
'experimental/oauth-auth',
'experimental/multi-user',
'experimental/rule-templating',
],
},
'getting-started/tips-tricks',
Expand Down
100 changes: 100 additions & 0 deletions docs/experimental/rule-templating.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Rule Action Templating

:::warning
This is an **experimental feature**. That means we’re still working on finishing it. There may be bugs, missing functionality or incomplete documentation, and we may decide to remove the feature in a future release. If you have any feedback, please [open an issue](https://github.com/actualbudget/actual/issues) or post a message in the Discord.
:::
:::warning
All functionality described here may not be available in the latest stable release. Use the `edge` images for the latest implementation.
:::

Rule action templating allows rules to dynamically set fields based on transaction data via meta programming inside the rule.

Setting the following fields with a rule template is currently supported:
- notes
- date
- amount
- payee (name)
- cleared (although no boolean helper functions are currently supported)

Actual uses [handlebars](https://handlebarsjs.com/) under the hood to process the rule templates. You can find more in depth information about how this works in [their guide](https://handlebarsjs.com/guide).

## Using rule action templating
You can toggle between the normal and template input modes by clicking the icon to the right of the action input box.

![How to enable rule action templating](/img/experimental/rule-templating/enable-rule-templating.png)

When the template input mode is active you can type your template into the input box as below. This example removes the string " 12345" from an imported payee and sets the payee to this new value.

![How to enable rule action templating 2](/img/experimental/rule-templating/enable-rule-templating-2.png)

## Variables

| Variable | Type | Notes |
|-----------------------|---------|-----------------------------------------------------------------------------------------------------------------|
| today | date | Today's date |
| account | id | |
| date | date | |
| payee | id | |
| imported_payee | string | |
| notes | string | |
| amount | number | This is stored without the decimal place. ie. 152 will be 15200. {{div amount 100}} can be used to convert back |
| cleared | boolean | |
| reconciled | boolean | |
| imported_id | id | ID of the transaction provided from an import source (eg. bank sync/QFX) |
| is_child | boolean | Flag for children in a split transaction |
| is_parent | boolean | Flag for the parent of a split transaction |
| parent_id | id | Set if is_child = true |
| schedule | id | |
| starting_balance_flag | boolean | Set if the transaction is a starting balance transaction |
| transfer_id | id | |

## Functions
### Mathematical

| Function | Arguments | Notes |
|----------|---------------------|-------|
| add | number1, number2... | |
| sub | number1, number2... | |
| div | number1, number2... | |
| mul | number1, number2... | |
| mod | number1, number2... | |
| floor | number | |
| ceil | number | |
| round | number | |
| abs | number | |
| min | number1, number2... | |
| max | number1, number2... | |
| fixed | number1, number2... | |

### Text

| Function | Arguments | Notes |
|------------|-----------------------------|------------------------------------------------------------------------------------------------------------|
| regex | value, regex, replacement | |
| replace | value, pattern, replacement | Mimics js replace. When pattern is not as /regex/flags it just uses raw value as opposed to {{regex ... |
| replaceAll | value, pattern, replacement | Mimics js replaceAll. When pattern is not as /regex/flags it just uses raw value as opposed to {{regex ... |
| concat | values... | Joins all arguments together |

### Date

| Function | Arguments | Notes |
|-----------|--------------|---------------------------------------------------------------|
| addDays | date, number | |
| subDays | date, number | |
| addWeeks | date, number | |
| subWeeks | date, number | |
| addMonths | date, number | |
| subMonths | date, number | |
| addYears | date, number | |
| subYears | date, number | |
| setDay | date, day | Overflows are handled, 0 will set to last day of month before |
| day | date | Extract the day from a date |
| month | date | Extract the month from a date |
| year | date | Extract the year from a date |
| format | date, format | |

### Other

| Function | Arguments | Notes |
|----------|-----------|---------------------------------------------------------|
| debug | any | Prints the arguments to the browser development console |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cd1b5f1

Please sign in to comment.