1 to 2 hours
1 Form, 6 Fields, 1 View, 2 Action Buttons
LotusScript and Formula
Yes, "Single Document" Approach
Conference room reservations, equipment rentals, vacation planner
Create the Database
Let's start building the calendar application by launching the Lotus Domino Designer client and creating a blank database. When the Designer client is running, select the File > Database > New menu options. Specify Meeting Calendar as the application title and MtgCalendar.nsf as the file name. Be sure to select -Blank- as the template type (see Figure 8.3).
Figure 8.3. New database dialog
It's a good idea to remove all spaces from the File Name field. Spaces can cause problems when working with web applications. For example, replace Meeting Calendar.nsf with MtgCalendar.nsf.
Create the Appointment Form
The appointment form captures the event start and end dates, total number of recurring appointment days, author, subject, and details. The number of appointment days will be automatically computed based on the start and end dates. Most of the work associated with calendar applications resides in the appointment form, including management of recurrent events.
To create a form, click the New Form button or select the Create > Design > Form... menu options. After the form has been created, add a descriptive text title such as Appointment at the top of the form and the following field descriptions down the left side of the form.
Your form should now look similar to Figure 8.4.
Figure 8.4. Appointment form with field titles
Define the Fields
Next, add the fields beside each field title as specified in the following table. To create a field, select the Create > Field menu options (see Figure 8.5). Be sure to set the data type, formula, and other properties in the properties dialog window for each field. The field name, type, and style will be defined in the properties dialog.
Figure 8.5. Field property dialog
By default, the properties dialog window will be displayed when the first field is created. Select Edit > Properties if the properties dialog window is not visible.
The field Formula will be placed in the Value or Default Value section of the Programmer's pane, located in the lower section of the Designer client. Select View > Programmer's Pane if the pane is not visible. Figure 8.6 shows the Programmer's pane for the StartDate field.
Figure 8.6. Default value formula for StartDate field
DEFAULT StartDate:= @If(@IsNewDoc; @Today; @Return(StartDate)); StartDate
In tab 1 of the properties dialog, set the Style to Calendar/Time control.
In tab 1 of the properties dialog, set the Style to Calendar/Time control.
@If(StartDate = ""; 0; EndDate = ""; 0; @BusinessDays( StartDate; EndDate));
This formula will automatically compute the total number of days associated with the calendar event based on the start and end dates.
Names, Computed when Composed
This formula will automatically compute the author's name.
Rich Text, Editable
Your calendar appointment form should now look like Figure 8.7.
Figure 8.7. Appointment form with fields added
Set the Form Objects and Properties
The Window Title displays in a tab at the top of the Lotus Notes client whenever a document is opened. The title helps make the application more user-friendly and can be set to any arbitrary value or text string. However, because the display space on the tab is limited, you should limit the text value. To set the window title, locate the Window Title section and add the following in the Programmer's pane (see Figure 8.8):
Figure 8.8. Window Title for Appointment form
The QuerySave event will be used to refresh the current document any time the document is saved. This will ensure that the most current data is displayed to the user any time the form is saved (e.g., when the user selects the File > Save menu options). Add the following to the QuerySave event located in the Objects section of the Programmer's pane.
Sub Querysave(Source As Notesuidocument, Continue As Variant) Source.Refresh End Sub
Finally, select the Design > Form Properties menu options. This will display the properties dialog window for the form. On tab 1, check the Automatically refresh fields setting in the Options section (see Figure 8.9). This option will refresh computed fields as you change the data on the appointment form. For example, when the start and end dates are changed, the total number of days value will automatically update.
Figure 8.9. Form database dialog
To complete the form, specify Appointment | Appt in the Name field of the form properties dialog. The vertical bar indicates the alias name for the form. This completes the setup of the appointment form. Save and close the form.
Always provide a form name and alias name. All code should then refer to the alias name. This provides greater flexibility to change the form name without impacting existing code and/or view formulas.
Create the Calendar View
The majority of the project is now complete. The only step remaining is the creation of the calendar view used to display the appointments. Whenever a database is created, a default viewcalled "(untitled)"is automatically generated. Select Views in the Design pane and double-click on it to open in edit mode.
The next step is to define the properties for the view. Select the Design > View Properties menu options. Set the name to Calendar and alias name to Cal. Change the view Style from Standard Outline to Calendar. This setting changes the appearance of the view from the traditional look to a graphical calendar display. After you change the view, the Domino Designer client will display a warning message similar to Figure 8.10.
Figure 8.10. Warning message when selecting calendar view
Click Yes to continue.
The calendar graphical display only appears in the Lotus Notes client and is not what you will see in the Designer client as the view is being developed.
Define the Columns
For this project, the view will include three columns. As mentioned in the architecture section, the first two columns are required for the calendar views. These columns will be hidden. The third column will display information associated with the appointment.
Column 1 is a hidden column and must contain the start date/time value sorted in ascending order. To set the properties for this column, click on the column header and select the Design > Column Properties menu options.
In tab 1, set the Title to Date. In tab 2, set the Sort type to Ascending and select Show multiple values as separate entries. This is the option used to show one document across multiple calendar dates. Now switch to tab 6 and select the Hide column checkbox (see Figure 8.11).
Figure 8.11. Hide column on tab 6 of the view property dialog
Column titles are not displayed in the calendar view. However, providing a column header name will help you and other developers understand the view design and column content.
With the column properties defined, next set the column value. In the Programmer's pane, change the display type from Simple Function to Formula and set the column formula to the following:
REM "Column1 contains the list of start dates"; REM "as defined in the appointment form"; DateList := @Explode(@TextToTime(@Text(StartDate) + "-" + @Text(EndDate))); @TextToTime(DateList)
The second column must contain the duration in order for the calendar to display correctly. This column will also be hidden. Select the Create > Append New Column menu options to add the new column. Select the Design > Column Properties menu options to display the column properties dialog window. In tab 1, set the Title to Duration. Then switch to tab 6 and select the Hide column checkbox.
With the column properties defined, next set the column value. For this project, the duration will be set to zero. In the Programmer's pane, change the display type from Simple Function to Formula and set the column formula to the following:
REM "Column2 contains the duration for the appointment"; REM "Set this column to zero, unless you set a start and"; REM "stop time for each appointment"; 0
The third column simply displays a text value for the calendar event. For this project, the appointment subject will be displayed on the calendar view. Alternatively, this column could contain the person, person and subject, or some other combination of document fields and text. This is the value that will be shown on the actual calendar view.
Select the Create > Append New Column menu options to add the new column. In the Programmer's pane, change the display type from Simple Function to Field and set the column formula to the following:
You may want to set the background color for the column to enhance the application usability. This will highlight the entry and help users locate calendar events on the view. To set the background color, select the third tab in the View properties dialog. The Background setting is located in the Entry section.
Set the View Objects and Properties
This project includes three methods for creating new appointmentsthe menu bar, an action button, and clickable calendar events. This will allow users to select the Create > Appointment menu options, click the New Appointment button (described later in this section), or double-click on a calendar date.
The RegionDoubleClick event allows users to double-click on a calendar date and automatically launch the new appointment form. When the form is displayed, the start date is populated with the date selected on the calendar.
This event also contains a data validation check to see if the selected date is before the current date. If the date is in the past, the user receives the prompt, "Date in past. Do you want to continue?" If the user selects Yes, the answer variable is set to 6 (which is a default value automatically set by the Lotus Notes application).
To configure this functionality, locate the RegionDoubleClick event in the Objects section of the Programmer's pane and then add the following LotusScript code. This code will create a new appointment if the date is today, in the future, or if the user answered Yes to create the record in the past. This routine is only executed if the user double-clicks on a calendar date.
Sub Regiondoubleclick(Source As Notesuiview) Dim doc As NotesDocument Dim workspace As New NotesUIWorkspace Dim uidoc As NotesUIDocument Dim view As NotesView Dim dateTime As New NotesDateTime("") Dim answer As Integer ' Display warning if selected date is in the past. Call dateTime.SetNow If Source.CalendarDateTime < dateTime.LSLocalTime Then answer%=Msgbox("Date in past. Do you want to continue?", _ 292, "Continue?") End If ' Create the appointment if date is in the past and user ' clicked, YES or create the appointment if date is in ' the future. If (answer% = 6) Or _ (Source.CalendarDateTime >= Cdat (dateTime.DateOnly)) Then Set view = Source.View Set uidoc = workspace.ComposeDocument ("", "", "Appt") Set doc = uidoc.Document doc.StartDate = Source.CalendarDateTime End If End Sub
This code can be added to the RegionDoubleClick event for any calendar view. This code checks to see if the date is in the past and prompts the user if they want to continue. To incorporate this feature into an existing database application, simply change Appt to the appropriate form name and add the code. This will make the application more user-friendly and enhance general usability.
Create Action Buttons for the View
Two action buttons will be created for the view. One button will be used to create new appointments. The other button will jump the calendar view to the current date.
To create the first button, select the Create > Action > Action menu options and name the button New Appointment. Close the properties dialog and add the following to the Programmer's pane.
To create the second button, select the Create > Action > Action menu options and name the button Today. Close the properties dialog and add the following to the Programmer's pane.
Optionally, you can add an icon to the action button. To add an icon, click on the action button and select the Design > Action Properties menu options. Then select an icon in the lower section of the properties dialog window.
Save and close the view. Congratulations, you have completed the project! If would you like to further customize the application, refer to Chapters 13 through 17 for additional enhancements. When you open the Lotus Notes client, your project should look similar to Figure 8.12.
Figure 8.12. Completed project
Project B Build a Conference Room Reservation System
An Introduction to the Lotus Domino Tool Suite
Getting Started with Designer
Navigating the Domino Designer Workspace
Domino Design Elements
An Introduction to Formula Language
An Introduction to LotusScript
Fundamentals of a Notes Application
Reference Library Applications
Design Enhancements Using LotusScript
Design Enhancements Using Formula Language
Miscellaneous Enhancements and Tips for Domino Databases
Application Deployment and Maintenance
Appendix A. Online Project Files and Sample Applications
Appendix B. IBM® Lotus® Notes® and Domino®Whats Next?