Reg Exp
Web Design
Notes Client
View of Todays Documents
For a recent project, there was a need to show (on the web) documents created "today". There are a number of ways to do this, including using time sensitive formulas (either @Today or @Now) in a view. This is a new way of doing it that doesn't involve time sensitive formulas in views or scheduled agents.

Since this view was web-only, I could take advantage of a trick using style sheets to get the effect I wanted (only showing documents created on the current date). First, let me point out that there are normally around 5 or so documents created per day, so I know that I'm going to be fine with the default of 30 documents in the view. So my view shows documents, sorted in descending order by date created. So documents created today will be at the top of the view, and simply opening the view on the web will have today's documents shown.

When you look at the view on the web, it will show the last 30 documents that were created. The next step is to hide the documents that were created earlier than today. This is done through the CSS property "display:none". So, in my view, I make sure that every entry has that class. The view column becomes:

"<div class=\"viewentry\">" ... "</div>"

where "..." is the formula that used to be in the view column. (Note - the view is set up as "treat view contents as HTML").

Inside the view template for the view, that class entry is set up to be hidden all the time. This is done in the HTML Head Content for the view template:

"<style type=\"text/css\"><!--" + @NewLine +
".viewentry { display:none; }" + @NewLine +
"//  -->" + @NewLine +
"</style>" + @NewLine

Now, when you look at the documents on the web, none will appear because of the CSS. Next we need to make sure that today's documents are shown. To do this, add a second class to every entry in the view. This class entry is specific to the date the document was created. So the view column becomes:

"<div class=\"viewentry D" + @Text(@Year(@Modified)) + @Right("0" + @Text(@Month(@Modified)); 2) + @Right("0" + @Text(@Day(@Modified)); 2) + "\">" ... "</div>"

Every view entry now has two classes defined. The first is "viewentry" for every entry. The second is D######## where the first four #'s are the year, the next two #'s are the month, and the last two #'s are the day. For example, if a document was created on January 1st, 2006, the second class name would be D20060101. (Note - adding a space between the two class names is how to get multiple classes defined for a single division on a web page).

Now we have to make sure that documents with a class value of today's date are shown. This is done through an update of the HTML Head Content for the view template:

"<style type=\"text/css\"><!--" + @NewLine +
".viewentry { display:none; }" + @NewLine +
".D" + @Text(@Year(@Now)) + @Right("0" + @Text(@Month(@Now)); 2)
+ @Right("0" + @Text(@Day(@Now)); 2)
+ " { display:block; }" + @NewLine +
"//  -->" + @NewLine +
"</style>" + @NewLine

The entry starting with ".D" is new to the HTML Head Content field. View entries that match the format of today's date will override the "display:none" with "display:block" and be shown. Entries that don't match the format of today's date will still have the "display:none" value (because there is no definition for the other class, so nothing overrides it) and not be shown.

No scheduled agents, no time-sensitive values in the view. Remember that this technique only works in web views. The speed won't be an issue because the default for the number of lines in the view will limit how many documents are shown (generally 30, but you have to check the server settings). Since there are (in my case) only around 5 or so documents created per day, there shouldn't be a case where documents that should appear are not appearing.

One final note: if users go to view the source, they will see all the documents. So this is another one of the cases where it's not a security feature. If you want true security you must use another method. But if you're just wanting to show today's documents, this technique is pretty easy to implement and gets the job done for web views.