I have a view selection formula
SELECT @If( @Date(@Now) = @Date(@Created); @All; @False)
and I want it to select all documents from the past 7 days rather than just today's.
Thanks in advance for any help.
views:
974answers:
4SELECT @If( @Date(@Now) < @Date(@Adjust(@Created(), null, null, 7, null, null, null)); @All; @False)
You need to be very careful of view selection formula that have dates in them.
If you use @Today or @Now then then Notes/Domino will always consider all of the documents in the view to be out of data and will have to rebuild the index every time it is accessed. This will be ok for very small databases, but a disaster in larger ones.
Some people will try and work around that by using a formula like @date("Today"). Notes/Domino will not recognise that as a Date/Time based formula, since it doesn't contain @Today or @Now, and will work initially. But you will find that the view will not remove old documents unless the index is fully refreshed, which can be tricky to arrange for.
The best way to deal with this is to have an agent run every night that updates the selection formula with the correct fixed date values. Jake Howlett at codestore.net has some excellent posts on doing this.
You need 2 parts. The view selection formula:
SELECT isnotyet7daysOld = @True
and an agent (or two) which run on schedule and on "when documents have been created or changed". The agent looks like this (both)
minDate := @Adjust(@Today;0;0;-7;0;0;0);
REM "There are no future documents";
tmpResult := @if(minDate <= @Created;@False;@True);
SELECT tmpResult != isnotyet7daysOld;
FIELD isnotyet7daysOld := tmpResult
For adjust you need 0 not null; null happens to work since there is no field or variable with the name null and @Formula is forgiving and makes the missing value 0. The trick here: you compute the value that the field isnotyet7daysOld should have for the selected documents (that would be the changed ones for the onChange agent or all on the scheduled agent) and then select to change only those where the result doesn't match. This way you minimize document updates. Also documents that get saved are updated directly. If you now add a hidden computed-when-composed field isnotyet7daysOld with @True as field value you capture all your document reliably. And you need to run the scheduled agent only once a night (0:01).
Here is what I did (I used @TextToTime("Today") instead of @Today to avoid the index rebuild per above warning):
SELECT (@Created) >= @Adjust(@TextToTime("Today");0;0;-7;0;0;0)
BTW, thanks for the above hints. I've been wanting to create a view like this for a long time. I'm a z/OS system programmer (mainframe) and kept having to rebuild this view weekly to get it current since the "canned" view design formula was not a relative date. I took the @TextToTime hint from the @Created example in Notes help (this had an example of getting documents in the current month). My Notes client is release 6.5.