Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feedback] Rule action templating #3606

Open
matt-fidd opened this issue Oct 8, 2024 · 6 comments
Open

[Feedback] Rule action templating #3606

matt-fidd opened this issue Oct 8, 2024 · 6 comments
Labels
experimental feature Related to an experimental feature feedback Single feedback thread for bug reports on a new feature rules Related to rules

Comments

@matt-fidd
Copy link
Contributor

matt-fidd commented Oct 8, 2024

Rule action templating allows rules to dynamically set fields based on transaction data.

To enable the feature - head over to experimental features and toggle the rule action templating feature flag. Next, go to the "rules" page and set up a new rule.

To use it, click the icon on the right hand side of the input box to toggle from "text" to "template" mode:
Text mode:
image
Template mode:
image

Then enter your template. For example, the below will replace the notes field with the VAT paid (standard VAT is 20% in the uk)
image

At the moment, templating is supported for setting:

  • notes
  • date
  • amount
  • cleared (although no boolean helper functions are currently supported)

Full list of available helper functions:

  • regex value regex replacement
  • add num1 num2 ...
  • sub num1 num2 ...
  • div num1 num2 ...
  • mul num1 num2 ...
  • mod num1 num2 ...
  • floor num
  • ceil num
  • round num
  • abs num
  • min num1 num2 ...
  • max num1 num2 ...
  • fixed num1 num2
  • day date
  • month date
  • year date
  • format date format
  • debug value (logs to console)

Full list of available variables that can be used

  • today (date)
  • account (id)
  • amount (number)
    • remember this is stored without the decimal place. ie. £152 will be 15200. {{div amount 100}} can be used to convert back
  • cleared (boolean)
  • date (date)
  • error (?)
  • imported_id (id)
  • imported_payee (string)
  • is_child (boolean)
  • is_parent (boolean)
  • notes (string)
  • parent_id (id)
  • payee (id)
  • reconciled (boolean)
  • schedule (id)
  • sort_order (number)
  • starting_balance_flag (boolean)
  • tombstone (boolean)
  • transfer_id (id)

Feel free to share your ideas, bug reports and feedback below.

@matt-fidd matt-fidd added rules Related to rules experimental feature Related to an experimental feature feedback Single feedback thread for bug reports on a new feature labels Oct 8, 2024
@youngcw
Copy link
Member

youngcw commented Oct 8, 2024

Some additional variables I would appreciate being added are:

  1. Current Balance of Account (extra bonus points for average monthly balance). This would be nice for automatically determining interest amounts that are included in a mortgage payment for example.

  2. Account balance on day. Useful for determining what a paid in full credit card payment will be dynamically based on current balance of the CC account within a window. (EX. Balance_today- Balance_one_month_prior = payment amount)

@UnderKoen
Copy link
Contributor

Some additional variables I would appreciate being added are:

  1. Current Balance of Account (extra bonus points for average monthly balance). This would be nice for automatically determining interest amounts that are included in a mortgage payment for example.
  2. Account balance on day. Useful for determining what a paid in full credit card payment will be dynamically based on current balance of the CC account within a window. (EX. Balance_today- Balance_one_month_prior = payment amount)

I think these could best be added as helper functions. Especially the second one.
We could use https://github.com/gastonrobledo/handlebars-async-helpers/ to make an helper that fetches on execution

@mullermn
Copy link

This looks incredibly powerful, I will turn this on and start playing with it.

My condolences to whoever eventually takes on the task of building a UI for this! 😃

@UnderKoen
Copy link
Contributor

I don't thing there will ever be an UI for this, (at most an helper to show which fields are available). As that it would most likely limit the usage of this function.

@UnderKoen
Copy link
Contributor

Maybe fun to share, my current rules with templating
image

@IsThisThingStillOn
Copy link

IsThisThingStillOn commented Oct 28, 2024

I'd love to see some examples of using the date functions. As of now I have only successfully got a result with {{today}}. {{day today}} for example doesn't bring up any result. {{date}} doesn't work.

What surprisingly worked was {{regex today "-[0-9]{2}-[0-9]{2}" "-11-01"}} to set the date.

But right now making date calculations doesn't seem to be supported at all, is that assumption correct? I'd love to see that as a feature. Along with other date functions (first of month, end of month etc.)

/E:
After fix #3749 day, month and year work as intended.

To everyone interested, the following rule template will move the transaction to the first of the next month (including changing the year):

{{add (year date) (floor (div (add (month date) 1) 13))}}-{{add (mod (month date) 12) 1}}-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
experimental feature Related to an experimental feature feedback Single feedback thread for bug reports on a new feature rules Related to rules
Projects
None yet
Development

No branches or pull requests

5 participants