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 requested that a project that was previously deployed in St. Louis also be deployed in Atlanta. Using this approach, you can use the content of the existing project document as the basis for the new project document. After the project document is created, the project manager can change all references from St. Louis to Atlanta, update the target delivery dates, and assign project members.

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 user interface.

Implementation

To 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


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