How to specify a default date?
I'm experimenting with a db to help schedule tasks for the coming gardening season. Many of the fields will be calculated in reference to our local "last frost date".
I created a date field titled "date last frost". Then in the screen where you edit the field attributes, I chose "required - yes" and "show in calendar - yes". So far, so good. But then I clicked on "default value", and have only two options, either "empty" or "today". If I choose "empty", when I'm adding a record to the db I can fill it in with my last frost date, but in every new record that field is empty.
Is there a way to specify that I want that field to come up pre-filled with "May 01, 2023"?
TIA for any insight.
7 replies
-
At the table level, there is a Trigger on new record. You can add the code:
'date last frost' := date(2023,05,01)
Now every time you click on the new record button, Ninox will fill in the date.
The issue here is you have to edit this code every year. Being once a year that is not bad.
You could try:
let lastRec := last(select currentTableName); 'date last frost' := lastRec.'date last frost'
This will find the last record in your table and then put the data in 'date last front' into the new record. I don't know if the last record will always have the most recent data, so that is a limitation.
-
Perfect! Just what I needed, thanks.
-
Hm. Well, I'm not quite there yet. I put your example in the "trigger after update" box in the screen where you define your field. But it didn't result in that value showing up in my records. Do I need to do some other procedure in addition, or maybe I should put it in a different place? TIA for your help.
'date last frost' := date(2023,05,01)
-
zenmom said:
I put your example in the "trigger after update" box in the screen where you define your fieldWhich field's Trigger after update did put it in?
-
I clicked on the "gear" icon, and then selected Edit Fields. Then I selected 'date last frost', which popped open the window for editing that field. I clicked on "More Options", after which I could see "Trigger after update"; I entered the snipped of code in the "Trigger after update" box. That seemed the most logical place to put it.
-
zenmom said:
Then I selected 'date last frost'Try putting the code in the Trigger after update of another field or at the table level.
-
Works now! Thanks.
Content aside
- Status Answered
- 1 yr agoLast active
- 7Replies
- 111Views
-
2
Following