Your Development & Design Resource
Functional events via CFD fields
09/30/2005 07:26 AM by Chris Toohey
*Authors Note: Have you ever had a solution that you didn't know just how far it could go or to what extent it could be used? At the time of this publishing, I have so far used what I'm going to cover in this article for as many as three seperate fixes to a given issue, and have come up with a few more things that I want to play around with. Hopefully it'll be as useful to you, the Domino Web Developer, as it is to me! In any event, if you can think of a better name for this article, by all means please let me know!
Computed For Display (CFD) fields are typically used in Domino applications to (we're talking the basics here gang...) and return computed information for display purposes (wonder how they got the CFD label huh?!) - not much function in that. You can however, add what's typically thought to be UI functional formula (meaning formula/commands that perform a given function) in a CFD field, which will act as it's own WebQueryOpen event and perform a number of given actions.
I'll give you a cookbook-style walkthrough on how I was able to use this approach to solve my issues (I will continue to update this article with more examples as I find them), which will hopefully not only showcase the possibilities of using such a method but also act to further detail just what it is I'm talking about!
The Page Counter
A very simple thing really: each time a page is read, add another hit to a hit-counter. Now, typically you would throw this into an agent and call it via the WebQueryOpen event, but as I already had something in there, I didn't want to muddy the waters...
What you'll need:
- A Computed number field called hitcounter on this form.
- A Computed For Display text field caled HTTP_Referer (CGI
- A Computed For Display text field called CFD_counter.
Computed to... well, we'll get to that..
Now that you have 3 fields on a form, it's time to do something with them. What we do with them, however, is based on how you want to handle your hit counter. I'll explain...
A basic hit counter tracks the number of page loads. This can be a non-realistic number due to many unforeseen factors, the most common being someone hitting Refresh/F5/etc. on their browser and reloading the page contents. Do you really want that to count as a hit? I didn't think so. But just in case, I've included two formulas below; the first a very simple counter and the second a more logic-driven counter!
FIELD hitcounter := hitcounter + 1
Simple huh? This formula would trigger on all page loads. For something a little more logic-driven, try this one:
@If(HTTP_Referer = ""; ""; @Do(FIELD hitcounter := hitcounter + 1) )
Again, very simple, but checks to see if there's something in the referer field. Otherwise the page load isn't taken into consideration. While this isn't the perfect formula (doesn't log, for example, bookmarked documents, etc.) it does start to add some logic to this approach.
The approach, using a CFD field to perform certain event-level functions, is
facilitated here via the
FIELD function. When the Domino
form/document loads, the CFD formula is executed. This formula then performs
the given action, which in this case is setting a field!
The Page Load Notification
Without getting into exactly what type of page this was... there was one fact that I'll be willing to share: when it was openned, I wanted to get immediate notification!
The beautiful thing about Domino: it contains on a pretty functional messaging solution. I had intended to utilize this solution, via emailing my cellphone and the cellphone of my partner onload of this page. Now, I could have written an agent and triggered it via the WQO event... but I again already had something running in there and didn't want to muddy the waters. I started with a CFD field...
- A Computed For Display text field caled Remote_Addr (CGI
- A Computed For Display text field called CFD_mailer.
As for my formula, I went with something that we could all recognize: a
subject := "Page Accessed. User IP: " + @Text(Remote_Addr);
The below code would send me an email message on every instance of the aforementioned page being loaded! A very simple, yet very powerful method in this authors opinion indeed!