store user preference information (e.g. as in your Notes mailbox). Most uses of
profile documents need lots of forms and dialog boxes and agents to let users
edit their preferences.
But without adding a single design element, you can use profile documents to
add a valuable feature to your application. Every time a user creates or edits
a document, you can remember the last value they entered in a particular field,
and automatically fill in that value as the default the next time they create a
document of that type.
Many variations are possible as to when you would choose to update the stored
default value. In the following example, I chose to store a new default value
in the profile document only when the user is saving a new document. I reasoned
that some users might be editing other users' documents, and wouldn't want the
Department value from the last document they edited to become their new default
value; only from the documents they themselves create.
You can do this with environment variables instead (@SetEnvironment and
@GetEnvironment functions). The advantage to using environment variables is
that the values you store can work across multiple applications. The
disadvantages are that different applications may interfere with each other by
using the same environment variable name inappropriately, and that environment
variables won't work when accessing an aplication from a web browser. Both
techniques have their place.
Suppose your field is called "Department", and odds are that every document a
user authors will probably have the same Department value in it because that's
the department they work in.
The Default formula for the field could be:
@GetProfileField("PersonalProfile"; "Department"; @UserName)
This pulls out the value previously stored in the profile document, if any --
the first time the user creates one of these documents, this value will be
undefined so the field will be left blank.
The Input Translation or Input Validation formula will be responsible for
saving the value entered by the user. Here's an example of doing it with the
Input Translation formula:
REM "assign a temporary variable with the trimmed value of this field.";
tmp := @Trim(Department);
REM "if the field isn't blank, and this is a new document being saved, store
the value in the user's profile document to serve as a default next time they
@If(tmp != "" & @IsNewDoc & @IsDocBeingSaved;
@SetProfileField("PersonalProfile"; "Department"; tmp; @UserName);
REM "Finally, since this is a translation formula, return the trimmed value.";