Prompt in LotusScript

The LotusScript Prompt function displays a popup window where the user can specify or select a value (see Figure 13.26). This function can be used to interact with the user and manage data content. For example, the function allows users to describe changes to a document as it is being saved or display a dropdown list of values that the user must select from. This latter option allows you to control the content stored in a particular document field.

Figure 13.26. Example of the Prompt function to display and select values

This routine illustrates how to create a prompt that contains a dropdown list of values. The values can be static (where values are hard coded) or dynamic (where values are created based on other design object values).

How It Works

This is a built-in Domino function. The Prompt function includes several parametersbutton style, title, caption, default choice, and a list of values. See Chapter 6 for additional information pertaining to the Prompt function.

ImplementationStatic Example

This first example illustrates how to implement the Prompt function with static, or hard-coded, values. After the user selects a value, it is stored in the Result object. A confirmation message is displayed to the user if the value is not blank.

Sub Click(Source As Button)

 Dim w As NotesUIWorkspace
 Dim s As NotesSession
 Dim db As NotesDatabase
 Dim doc As NotesDocument
 Dim choices (1 To 3) As String
 Dim Buttons as Integer
 Dim Title as String
 Dim Caption as String
 Dim Default as String
 Dim Result as String

 '-----------------------------------------------------
 ' Set object values
 '-----------------------------------------------------
 Set w = New NotesUIWorkspace
 Set s = New NotesSession
 Set db = s.CurrentDatabase

 '-----------------------------------------------------
 ' Set the choices
 '-----------------------------------------------------
 choices(1) = "Choice one"
 choices(2) = "Choice two"
 choices(3) = "Choice three"

 '-----------------------------------------------------
 ' Set prompt title, buttons and default
 '-----------------------------------------------------
 Buttons = PROMPT_OKCANCELCOMBO
 Title = "Select a value"
 Caption = "Choose one"
 Default = choices(1)

 result$ = w.Prompt (Buttons,Title,Caption,Default,Choices)
 If result$ <> "" Then
 Msgbox result$,, "You selected:"
 End If

End Sub

 

ImplementationDynamic Example

In this second example, the code loops through the documents in a particular view and dynamically generates the prompt values by building a list based on a particular field. To implement this solution, insert a valid view name and field name.

Sub Click(Source As Button)

 Dim w As NotesUIWorkspace
 Dim s As NotesSession
 Dim db As NotesDatabase
 Dim doc As NotesDocument
 Dim view As NotesView
 Dim choices () As String
 Dim Buttons as Integer
 Dim Title as String
 Dim Caption as String
 Dim Default as String
 Dim Result as String
 Dim I as Integer

 '-----------------------------------------------------
 ' Set object values
 '-----------------------------------------------------
 Set w = New NotesUIWorkspace
 Set s = New NotesSession
 Set db = s.CurrentDatabase
 Set view = db.GetView("VIEW")

 '-----------------------------------------------------
 ' Loop through view to build choice selection
 '-----------------------------------------------------
 i=0
 Set doc = view.GetFirstDocument
 While Not(doc Is Nothing)
 Redim Preserve choices(i)
 choices(i) = doc.FIELD(0)
 i = i + 1
 Set doc = view.GetNextDocument(doc)
 Wend

 '-----------------------------------------------------
 ' Set prompt title, buttons and default
 '-----------------------------------------------------
 Buttons = PROMPT_OKCANCELCOMBO
 Title = "Select a value"
 Caption = "Choose one"
 Default = choices(1)
 result$ = w.Prompt (buttons,title,caption,default,choices)
 If result$ <> "" Then
 Msgbox result$,, "You selected: "
 End If
End Sub

Note

This routine can produce duplicate values if the field values are not unique. Additional programming logic is required to manage duplicate values.


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

Calendar Applications

Collaborative Applications

Reference Library Applications

Workflow Applications

Web Applications

Design Enhancements Using LotusScript

Design Enhancements Using Formula Language

View Enhancements

Sample Agents

Miscellaneous Enhancements and Tips for Domino Databases

Data Management

Security

Application Deployment and Maintenance

Troubleshooting

Appendix A. Online Project Files and Sample Applications

Appendix B. IBM® Lotus® Notes® and Domino®Whats Next?



Lotus Notes Developer's Toolbox(c) Tips for Rapid and Successful Deployment
Lotus Notes Developers Toolbox: Tips for Rapid and Successful Deployment
ISBN: 0132214482
EAN: 2147483647
Year: N/A
Pages: 293
Authors: Mark Elliott

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net