Subject: How 2 create new doc in sep. db via script - herez the code
Julie, (and the other 2 posts),Thank you very much for the comments. I tried to hear what each of you stated and put it together. I’m still not sure if it’s right and there are a few details I’m sure to be missing. Could you please review and let me know where I need to add or change things.
Thank you once again for your quick assistance.
Steve
'…Click on Action Button
’
'…define environment and UIDoc and make available several fields it contains
Dim Session As NotesSession
Dim ws As New NotesUIWorkspace
Dim db As NotesDatabase
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Set Session = New NotesSession
Set db = Session.Currentdatabase
Set uidoc = workspace.CurrentDocument
Set doc = uidoc.Document
’
dim lastreferencenumber as variable '…to be used to place onto new reference document
’
'…open system db on same server
Set sysdb = session.getdatabase(db.server,”ReferenceDb.nsf”)
’
'…open system view to lookup the last document and get the last saved reference number (a key field)
Set sysview = sysdb.getview(“referencenumberview”)
Set sysnav = sysview.CreateViewNav
Set sysentry = sysnav.GetLast
Set sysdoc = sysentry.Document
'…place reference number into variable to use later
set lastreferencenumber = sysdoc.referencenumber(0)
'…done with system view and document, can close these now, (need sysdb still)
’
Call sysdoc.Close(True)
Call sysview.Close(True)
'…create a new document in system database
Dim newsysdoc As NotesDocument
'…??? how do I set the form name to the newly created document in the next line of code or after that?
Set newsysdoc = sysdb.CreateDocument
’
'…populate fields from UIDoc onto new system doc
newsysdoc.field1=doc.field1(0)
newsysdoc.field2=doc.field2(0)
newsysdoc.field3=doc.field3(0)
newsysdoc.referencenumber=lastreferencenumber
'…New reference document is created with several fields and new id, save it now
Call newsysdoc.Save (True, True)
'…Close sysdb and save UIDoc, then close UIDoc
Call sysdb.Close(True)
Call doc.Save (True, True)
Call doc.Close(True)