When I Copy a document to another database with LS, does not copy fields

I am trying to run code that copies the current document to another database, using a form that is located in both DB’s. The document copies ok, but it does not sopy the field info. Here is the code that I am using:

Dim session As New NotesSession

Dim db As NotesDatabase	

Dim testdb As New NotesDatabase ( "", "test1.nsf")

Dim doc As NotesDocument

Set db = session.CurrentDatabase

Set doc = New NotesDocument( db )

doc.form = "Test"



Call doc.Save (False, True)

Call doc.CopyToDatabase( testdb )

End Sub

Can someone please help!! Also, is there a way to delete and close the document after the script as ran? Thanks in advance.

Subject: When I Copy a document to another database with LS, does not copy fields

Well, you need to think a bit about what you are doing here.First you instantiate a new document with the ‘Set doc …’ statement.

Then you set one (1) item in that new document - the ‘Form’ item.

You then copy this new document to the target db.

Of course you won’t get any fields copied - there are no fields in your ‘doc’ document!

You start by saying you want to copy the ‘current’ document, but you are copying your new document, nothing else.

To copy the ‘current’ document, this code in a form action will work.

Dim session As New NotesSession

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim db As NotesDatabase

Dim testdb As NotesDatabase

Dim doc As NotesDocument

Dim docNew As NotesDocument

Set db = session.CurrentDatabase

Set testdb = session.GetDatabase(“”, “testdb.nsf”)

Set uidoc = ws.CurrentDocument

Set doc = uidoc.Document

Set docNew = doc.CopyToDatabase(testdb)

Call docNew.ReplaceItemValue(“Form”, “Test”)

Call docNew.Save(False, True)

Subject: RE: When I Copy a document to another database with LS, does not copy fields

Thanks for your help, you have to forgive me, I am new at LS. When I run your new script, I receive the following error:notes error: invalid or nonexistent document

Subject: RE: When I Copy a document to another database with LS, does not copy fields

OK, we all have to start somewhere.

First of all, read the helpfile and learn how to use the LotusScript debugger. That will show you exactly which instruction is causing the error.

Did you really put the code in a form action button? It should work from there.

If you want the code to work from a view action button, you must do it in another way. I won’t go into those details here unless you need that.

Subject: When I Copy a document to another database with LS, does not copy fields

The document you are copying contains only one item, Form, with a value of “Test”. I think this is what you want:

Dim session As NotesSession

Dim db As NotesDatabase

Dim testdb As NotesDatabase

Dim doc As NotesDocument

set session = new notessession

Set db = session.CurrentDatabase

set testdb = new notesdatabase(“”,“test.nsf”)

Set doc = db.createdocument

with doc

call .relaceitemvalue(“Form”, “Test”)

on error resume next

call .computewithform(false,false)

on error goto 0

call .save(false,false)

call .copytodatabase( testdb )

end with

The call to .save on line 15 is probably not necessary.