Link to home
Start Free TrialLog in
Avatar of ttennant
ttennant

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of Arunkumar
Arunkumar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Arunkumar
Arunkumar

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.
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.
Avatar of ttennant

ASKER

Thanks.  The code worked great.
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.