Tip: Making documents dynamic in read mode with hide-whens
Wed 15 Dec 2004, 12:31 PMTweet
by Ben Langhinrichs
It is always surprising to me how I learn new things about Notes every day, given that I have been developing with Notes for about ten years (is that possible?). Here is a tip about something I did know, and assumed others did as well, but obviously not all do.
Shlomo Beth Nahrin posed this question in the Notes 6 forum:
I want to hide with buttons a table with two rows.
When the user clicks the button1, hide row1, and clicks button2, hide row2.
Sure it's easy, with creating a field and use the contents of that field in the hide when formula.
But how can I solve it in readmode. I don't want to create an environment varible or any technical documents in the backend.
The answer given
Pretty straightforward question, but two respected developers and frequent forum question-answerers, Stan Rogers and Graham Richards, wrote back that it wasn't possible. Rather, Stan seemed to indicate it wasn't possible, and Graham came right out and said:
If you are talking about the Notes Client, this won't work in read mode - Notes will only "process" things like hide-whens once as the document is opened. You can't change the display of the document while it's open. (I can't offer help if this is for the web)
The correct answer (or "what Stan and Graham learned today")
But they are wrong. One of the odd tidbits I've picked up over time is that you can modify the front end document and act on those changes in read mode. I built a really slick demo for the Partner Forum with a whole questionaire that works that way, including allowing you to answer questions and totalling your score, all in read mode and not ever changing the document on disk. But on to the solution. Simply make a button or hotspot or form action with the formula:
FIELD MyControl := "Yes";
and another with the formula
FIELD MyControl := "";
and then use hide-when formulas in the table so that the first row has the hide formula:
MyControl = "Yes"
and the second has the hide-when formula:
MyControl <> "Yes"
and then you can switch which one shows in read mode. Note that if you run this in edit mode, it will save the last value set, but in read mode it won't. There doesn't even need to be a MyControl variable on the form, unless you want to set a default value. I usually use a default value of "", since that will work if the field doesn't exist at all. I posted a working demo in the forum so you can go try it out for yourself.
The additional information (or "what I learned today")
And lest you think I am smug, I learned something new as well. I thought this technique would only work in the Notes client, but as you will see in the demo, it works from the web as well. I never knew that, so Stan, Graham and I all learned something new today. I can't wait to find out what I will learn tomorrow.
Copyright © 2004 Genii Software Ltd.
What has been said:
250.1. Stan Rogers (12/15/2004 12:08 PM)
You know, Ben, most of what I've actually learned over the years has come from NOT listening to what people tell me and just, well, trying things. Using FIELD to modify the front-end document is one of those cases where I let other people's taboos guide me. I've got to get more curious. After all, it ain't broke 'til I can't duct tape it back together, right?
250.2. Graham Richards (12/15/2004 12:40 PM)
I don't mind being proved wrong (esp. when I learn something) and I *really* don't mind being proved wrong by Ben :-)
Great example Ben - Love the humorous approach.
Now, if only this worked with Action Buttons ... I'm sure you can't refresh them, and am looking forward to being proved wrong again !
250.3. Ben Poole (15/12/2004 17:48)
Doh! You live and learn... Thanks Mr. L ;o)
250.4. Tim Tripcony (12/21/2004 09:17 AM)
Yet another approach: when creating a table, one of the options for table type is programmatic. On the last tab of the table properties, set a table name (i.e. "FormulaTable"), then set a name for each row (i.e. "RowOne", "RowTwo"). Then code each button to set the field $
FIELD $FormulaTable := "RowOne";