Copy to New Document and Edit New

When you click a button (button1) in a form where an existing document (doc1) is displayed on the web, I want to be able:

  1. to create a new document (doc2) which copies the exact contents of the currently displayed document (doc1);

  2. to display and edit the newly created document (doc2); close the previous doc1.

  3. by clicking another button (button2), submits and saves the newly created document (doc2) with the user changes; and changes the status of the first doc (doc1) and saves it too.

How I did it so far but failed:

  1. On click of the button 1, @Command([EditDocument]) ----- this is doc1.

  2. On click of button 2,

@Command([ToolsRunMacro]; “CopyDoc”);

@SetField(“LastUpdated”; @Today);

@Command([FileSave]); - saves doc2

@Command([FileCloseWindow])

I call a macro (lotuscript)- Copy Doc with the ff. code:

Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc, curdoc As NotesDocument

Dim newdoc As NotesDocument



Set db = session.CurrentDatabase

Set curdoc = session.DocumentContext  (doc1)



Set doc = db.GetDocumentByUNID (curdoc.UniversalID)  (hoping it will pick up the original field values of doc1 but didn't)

Set newdoc = db.CreateDocument

Call doc.CopyAllItems(newdoc, True) (copies NOT the original field values of doc1 but new values changed by the user)

newdoc.Status = "Closed"

Call newdoc.Save(True, False, False)

End Sub

I also tried doing it this way:

  1. On click of the button 1, I have the ff. code

@Command([EditDocument]); — refers to doc1

tempid := @DocumentUniqueID; — assigned temp variables

tempcountry := Country;

templastupdated := LastUpdated;

temppmemergencytype := PMEmergencyType;

@Command([CloseWindow]); ---- close doc1.

@Command([Compose]; “Assessment”); ---- create doc2

@SetField(“UID”; tempid); — retrieve the temp variables and set the field values

@SetField(“Country”; tempcountry);

@SetField(“DisplayCountry”; tempcountry);

@SetField(“LastUpdated”; templastupdated);

@SetField(“PMEmergencyType”; temppmemergencytype);

@Command([RefreshWindow])

Problem in the above code is that I get a new document (doc2) but it is blank and it does not show the field values from the doc1.

Thanks and appreciate in advance for any help.

Subject: You are on the right track with your LotusScript solution…

However you need to get to the new document in the web. Try:Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument, curdoc As NotesDocument  'You must type all vars

'Your original Dim was: Dim doc As Variant, curdoc As NotesDocument

Dim newdoc As NotesDocument



Set db = session.CurrentDatabase

Set doc = session.DocumentContext



Set newdoc = db.CreateDocument

Call doc.CopyAllItems(newdoc, True) 'copies all items to the new document

doc.Status = "Closed"  'I assume that you wanted to close the original document, not the new one.

Call newdoc.Save(True, False, False)

Print |<script>|

Print |<window.location = "/YourView/| + newdoc.UniversalID + |?editdocument";|

Print |</script>|

End Sub