Go to layout [Daily]
Show All Records
Sort [Restore ; no dialog ] //sort by date in ascending order so most recent date is last record
Go To record/Request/Page [last]
Set Variable [$Date ; value: Daily::Date ]
Exit Loop if [Get ( CurrentDate ) > $Date ]
Set Variable [$Date ; value: $Date + 1 ]
Set Field [Daily::Date ; $Date]
Thanks! That's more than I was hoping for, and it seems to work as expected.
Actually, now that I looked more closely, it's not quite right: this will start at the last record, which will (more than likely) be today's date, due to the run-at-launch script. What I need the script to do is parse through the existing entries in the table, and only insert records if there's not a match. For example, the data for the last 10 days might look like this (assuming today = Feb 3):
The brute force method would be to set the start date to January 1st, and then run a find for January 1st in the table. If it's not found, create the record. If it is found, skip forward one day, then search for January 2nd. Repeat until the check date equals today's date.
But I was hoping to avoid running that many searches, especially as the year progresses ... but thinking it through, I don't see a more elegant solution.
OK, progress, and a solution! I implemented my brute force script, and while doing so, thought of a way to speed things up. The script basically does what I said above: it starts at January 1st 2012, and then searches on each date from there through today. If any records are missing, they're added. It works, but takes a bit of time.
The timesaving bit is that I'm now writing today's date into a separate table, and I then look up that value as the starting point the next time I run the script - because any dates before that will have been fixed by the last run of the script.
Thanks for the code idea that got me started going in the right direction! (If anyone wants me to post my brute force script, just ask.)
Once you have the gaps filled in. The script I posted can be used to prevent the occurence of any new ones. (Used that script on one of my systems for most of a year until I thought to replace it with a script that is run once a day from a server schedule to do the same thing.)