Generate a New Document by Duplicating an Existing Document
This routine illustrates how to create a new document using field values from an existing document. Let's say, for example, that you have a database that tracks projects, and a customer has just
How It Works
The
CopyAllItems
method associated with the
NotesDocument
class is used to obtain all object values and assign them to a new object. Using this method, all object values of one document (
doc
) are assigned to a second document (
newdoc
). If multiple documents are selected in the view, the code uses the first selected document as the basis for the new document. This solution creates the new document through back-end objects and then displays the document in the
ImplementationTo implement, create an action button on a view and insert the following LotusScript code in the Programmer's pane. Optionally, modify or clear field values associated with the form on the new document prior to calling the Save method.
Sub Click(Source As Button)
Dim s As NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim w As NotesUIWorkspace
Dim doc As NotesDocument
Dim uidoc As NotesUIDocument
Dim newdoc As NotesDocument
'-----------------------------------------------------------------
' Set object values
'-----------------------------------------------------------------
Set w = New NotesUIWorkspace
Set s = New NotesSession
Set db = s.CurrentDatabase
Set collection = db.UnprocessedDocuments
'-----------------------------------------------------------------
' Check if select item is a document
'-----------------------------------------------------------------
If collection.count = 0 Then
Msgbox("Please select a document. " +_
"The current item is a ""category"". ")
Exit Sub
Else
'-----------------------------------------------------------------
' Make a copy of the existing document
'-----------------------------------------------------------------
Set doc = collection.GetFirstDocument
Set newdoc =New NotesDocument(db)
Call doc.CopyAllItems(newdoc, True)
'-----------------------------------------------------------------
' Reset/Update field values
'-----------------------------------------------------------------
newdoc.
FIELDA
= ""
'-----------------------------------------------------------------
' Display newly created document
'-----------------------------------------------------------------
Set uidoc = w.EditDocument (True, newdoc)
End If
End Sub
|
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
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 WorksThis 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 ExampleThis 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
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. |

Mastering XPages: A Step-by-Step Guide to XPages Application Development and the XSP Language

XPages Extension Library: A Step-by-Step Guide to the Next Generation of XPages Components

Survival Guide for Lotus Notes and Domino Administrators

IBM Lotus Domino: Classic Web Application Development Techniques