1 of 1 people found this helpful
a very dirty way of doing it would be:
Sort Records - Date - ASC
Go To Record - First
Exit Loop If - table::dateField => Get(CurrentDate)
Go To Record - Next (exit after last)
This would go through all the records, starting from the oldest one, and stop whenever it met a record that had today's date (or later, if not today).
There's probably a more elegant solution.
A couple of other options:
A. You could count the number of records with a date larger than today (through a relationship or, if you're using v12, using the ExecuteSQL function). Then use the Go to Record/Request/Page script step with a calculation (count + 1).
B. Find for today, then Show All Records. Your current record will still be one of the first found set.
Thanks for the very quick response.
I think your solution is close, but not quite right. If I enter >= it go to any records that is today or later... Which could be six months from now. If you see what I mean?
I need it to go to "today", or the closest day that has an entry, even if there are hundreds of records beyond.
Like I say, I'm sure your solution is very close to what I need. Have you any further suggestions?
Thanks for your response also.
A. I'll definitely try this, thanks. I've not used the ExecuteSQL function before, but I'll look into it.
B. A similar situation to Mike suggestion, I think. There won't necessarily be an entry for "today", so I need a script that can find "the next closest" record. I hope this makes sense.
What I would like to be able to do is scroll to / go to "today's date", whilst continuing to show all records.
And if there is no date just go to the next one? Here is another approach:
Create a calculation (result is date, unstored) in your table and call it Today with:
Get ( CurrentDate )
Create another table occurrence of your table and join them as:
Data::Today ≤ Data 2::yourDate
Then it is a single script-step of:
Go To Related Record [ Data 2 ; using current layout ]
... and do NOT check anything below (leave all unchecked). The result is that it will jump to the current date (or one day later) no matter where your cursor starts in the record set, the found set, or how it is sorted. With this, you do not lose your found set.
OK, this definitely isn't elegant, but I think I have a solution (using both of your suggestions in some way, Mike and Debi):
# Find closest date to today
Show All Records
Enter Find Mode 
Set Field [Table:DateField, "//..."]
Perform Find 
Sort Records (ascending)
Go to Record [Last]
# Remember the closest date
Set Variable [$closest; Table:DateField]
# Show all records and go to closest date
Show All Records
Sort Records (ascending)
Go to Record [First]
Exit Loop If [Table:DateField = $closest]
Go to Record [Next, Exit after last]
This seems to work...!
Thanks again for all your help.
Thanks for this. I've found a solution via a script, I think -- see below -- but I can see that your solution would work as well.
Sure. But really a multiple-find script which finds, loops, sorts ... when what I presented is a single step and none of that is required at all? Speed diffrence alone will be huge. You might want to take a look again. Would it help if you had a quick file?
Hmm... Is another table occurance a better / cleaner / simpler solution than a script? I accept that it's a messy script!
I'm genuinely asking, btw. I'm a bit of a newbie at this!!
Thanks again for your help.
You are not adding another table but only an occurrence (representation of the table). It is a cleaner solution when it:
- Does not change your existing sort order + no sorting at all needed
- Does not change your existing found set + no finding at all needed
- Will be at least 5 times faster.
- Administering that script will be more difficult months down the road if you need to change something; not so with a single-step of GTRR
- Less chance that something can go wrong ...
Yes, it is far better in this case. I use scripted finds all the time and I prefer them in many cases but this isn't one of them (sorry Debi and Mike, I think you know this as well and just didn't think of it in the moment).
Message was edited by: LaRetta
I'll implement your solution now