Auto create record on first day of the new year
I have a table ( Invoice Summary) which summarises the monthly and quarterly totals from my invoice table.
Each record in this table has a number field where I enter the year I want to summarise and a bunch of formula fields which carry out the various calculations.
Whilst it's easy to create a new record and fill in the year, I'm wondering if there is a way to auto-create a new record and fill in the year the first time I open Ninox in the new year (calendar or financial)?
I have a few other tables where this would be useful (such as my Tax table).
One way I'm thinking that this could work would be to add the formula to "trigger on new record" part of my invoice table that first checks if a record exists for the current year and if not creates this record.
Not quite what I want but would be a work-around.
Either way I'm not quite sure how to script this so would be grateful for any help
Cheers
Michael
7 replies
-
Hi Michael
Michael said:
One way I'm thinking that this could work would be to add the formula to "trigger on new record" part of my invoice table that first checks if a record exists for the current year and if not creates this record.This is the way to do it, but put your code in 'Trigger after open' (found in Options). This runs when the app is first opened.
If count(select 'Invoice Summary' where Year = year(today())) = 0 then create('Invoice Summary').(Year := year(today())) end
Regards John
-
Thanks John. That looks perfect. I assume I could also put this in the "on open" global script for the database.
-
Why use a Summary table at all? Having 12 monthly and 4 quarterly formula fields in a single Summary record for each year could cause a speed issue presuming you have quite a lot of invoices per year and many years worth moving forward. That’s a lot of calculations on a lot of data. Why not just create Views of the original Invoices table and group by year, quarter, or month as needed.
Content aside
- 2 yrs agoLast active
- 7Replies
- 111Views
-
3
Following