How to create new document in separate database using script

I am new to scripting and have an immediate need to perform the features formula does not. It is so confusing, and I need a reference for things like this. If you know of a good resource, please let me know.

Create a new document in a separate database that contains several fields from the currently opened document. The newly created document has to have a reference number, which can be obtained by the last document in the key view in the second database. It needs to be incremented by 1, and saved on the new document. Both documents then need to be saved and the key view index to be refreshed in order to elimnate duplicates. I hope that someone good at scripting can provide me with an example that won’t take them much time.

Thanks,

Steve.

Subject: How to create new document in separate database using script

The Help is one of the best resources you’ll find.

Have a look at the examples on the following Help topics - working through them and combining them should get you somewhere near:

NotesDatabase class

NotesDatabase class, CreateDocument method

NotesView class

NotesView class, GetLastDocument method

NotesDocument class, ReplaceItemValue method

Have a go and see how far you get. If you get stuck, post your code and we’ll see what help we can give you.

HTH

Julie

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)

Subject: How to create new document in separate database using script

Steve,

To get a handle on a seperate database…

dim sep_db as new notesdatabase(server, filename)

To create a new document in the seperate database…

dim newdoc as new notesdocument(sep_db)

To populate the fidls in the new document, you will need to have a handle on the current document. Then it is a case of going through them…

newdoc.Field1=doc.Field1(0)

newdoc.Field2=doc.Field2(0) etc etc (assuming there are no multi-value fields)

To save a document…

call newdoc.Save(true, true) NotesDesigner Help will document the parameters

To get a handle on a view…

dim view as notesview

set view=sep_db.getview(viewname)

To get the last document…

dim lastdoc as notesdocument

set lastdoc=view.getlastdocument

You now have a handle on the last document and can get any field value from it. EG:

latestreference=lastdoc.ReferenceNumber(0)

Hope this points you in the right direction

Mike

Subject: How to create new document in separate database using script

Hi Steve,To create a new document you can use the

Set notesDocument = New NotesDocument( notesDatabase )

If you are very new to Lotus Script and have no idea what I am talking about then you will need to get yourself a book. If you have had any experience with VB or such languages then you will pick it up easily.

The notes Help is really good, and gives you examples you can copy. Go to the index and search for notesdocument and you will find what you need to copy into your code

Susan