How can I implement a "copy from" button to copy a document.

ttennant
ttennant used Ask the Experts™
on
I want to create a "copy from" button that will let a user create a document from an existing document so they do not have to fill out the entire form if just one field or so will be changed.  
The agent should be able to:
   Create a new document from an existing document
   Let the user pick which existing document to copy from
   This new document should be left in the edit mode so the user can edit the fields they want to before closing.

Thanks.

Tim
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Write this in a View Action or an Agent.

Dim ss As New notessession
     Dim db As notesdatabase
     Dim dc As notesdocumentcollection
     Dim selecteddoc As NotesDocument
     Dim newdoc As NotesDocument
     Dim uidoc As NotesUIDocument
     Dim ws As New NotesUIWorkSpace
     
     Set db = ss.CurrentDatabase
     Set dc = db.UnprocessedDocuments
     If dc.Count <> 1 Then
          Msgbox "Please select only one document to Clone"
          Exit Sub
     Else
          Set selectedDoc = dc.GetFirstDocument
          Set newDoc = db.CreateDocument
          Call selectedDoc.CopyAllItems( newdoc )    
          Set uidoc = ws.EditDocument(True , newDoc)
     End If    

-Arun.
Note: This action wont save the document until a manual save is performed on the opened document.
Nice code, Arun.  Stripped right down to what counts.
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

You know what ?  I just wrote it without testing and when i tested it worked just as intended to work at the first attempt.  You are the second person to appreciate and the first person was myself.

LOL !

:-)
Arun.

Author

Commented:
Thanks.  The code worked great.

Author

Commented:
I had one field that was set up as a unique identifier and so i had to modify the code so that this field would still be unique (instead of being copied).  Here's the result:

Dim ss As New notessession
Dim ws As New NotesUIWorkSpace
     
Set db = ss.CurrentDatabase
Set dc = db.UnprocessedDocuments
     
Set view = db.GetView( "Index" )  
Set doc = view.GetFirstDocument
     
highestNumber = doc.ColumnValues( 0 )

While Not ( doc Is Nothing )
        currentNumber = doc.ColumnValues( 0 )
     Set doc = view.GetNextDocument( doc )
     If currentNumber > highestNumber Then
          highestNumber = currentNumber
     End If
Wend
indexNumber$ = highestNumber +1
     
If dc.Count <> 1 Then
        Msgbox "Please select only one document to Clone"
     Exit Sub
Else
     Set selectedDoc = dc.GetFirstDocument
     Set newDoc = db.CreateDocument
     Call selectedDoc.CopyAllItems( newdoc )    
     Set uidoc = ws.EditDocument(True , newDoc)
     Call uidoc.FieldSetText("Index", indexNumber$)
End If    

Thanks again for the help.
Thanks for the update.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial