Copyitem to create new document in different DB

I’m having fun tonight!

I have a DB created using the 4.5 NAB as a template. It’s been tweaked over the years with many new fields and views added. It’s used as a rolodex of people outside the company and is integrated into our emarketing, event invitation, and targeted mailing systems.

So what’s my problem? People now want to be able to copy entries from this “rolodex” to their 6.5 personal address books.

If I use copytodatabase(destdb) like in the CopyToPAB agent I run into three problems:

a. the form name in the rolodex is no longer “Person”

b. Some of the field names (mostly business address fields) have changed.

c. I’m copying a bunch of unnecessary fields.

If I use CopyAllItems I can eliminate problem “a” above but still have “b” and “c”.

If I use CopyItem I can eliminate all three problems but it’s going to be long and tedious to set up.

Here’s where I’m at. Does it look like the right approach?

It would be great to get some feedback. Lotus script is not something I’m good at. I just cut, paste and pray.

Thanks

Dim s As NotesSession

Dim sourcedb As NotesDatabase

Dim destdb As NotesDatabase

Dim sourcenote As NotesDocument

Dim sourceview As NotesView

Dim destnote As NotesDocument

Dim destview As NotesView

Dim documents As NotesDocumentCollection

Dim Item as Notesitem

Sub Initialize

Set s = New NotesSession

Set sourcedb = s.CurrentDatabase

Set destdb = New NotesDatabase("", "names.nsf")

Set destview = destdb.GetView("($Users)")

Set sourceview = sourcedb.GetView("($Users)")



Set documents = sourcedb.UnprocessedDocuments

If documents.Count = 0 Then Exit Sub

DocsCopied = 0

For n = 1 To documents.Count

	Set sourcenote = documents.GetNthDocument(n)

	ProcessDocument

	If StopProcessing Then Exit For

Next

End Sub

Sub ProcessDocument

Set destnote=destdb.createdocument

Set item = sourcenote.GetFirstItem("Firstname")

Call item.copyitemtodocument(destnote, Firstname)

Set item = sourcenote.GetFirstItem("Lastname")

Call item.copyitemtodocument(destnote, Lastname)

Set item = sourcenote.GetFirstItem("StreetAddress_Pr_Bu")

Call item.copyitemtodocument(destnote, OfficeStreetAddress)





destnote.form="Person"

destnote.save True,False

End Sub

Subject: Copyitem to create new document in different DB

As per the code, you are copying the field values one by one from source to destination.

Your code looks good, except for GetNthDocument(n). GetNthDocument method is not recommended as it affects the performance of the system.

Instead use -

set documents = sourcedb.unprocesseddocuments

if not documents is nothing then

set sourcenote = documents.getfirstdocument

do until sourcenotes is nothing

ProcessDocument

set sourcenote = documents.getnextdocument(sourcenote)

loop

end if

–Phani

Subject: Copyitem to create new document in different DB

I think it’s close.

It runs without errors. But I do not see the new document.

any thoughts would be appreciated.

Thank you

Subject: RE: Copyitem to create new document in different DB

Person Documents in Local Names & Address Book have a field called Type which should be set to either “Person” or “Company”.In your case it should be set to “Person”.

Add the following line in the ProcessDocument function before the save :

destnote.Type=“Person”

You can also open your local names and address book to study the design and get an idea how the whole thing works.

cheers!!

Ashish

Subject: RE: Copyitem to create new document in different DB

Thank you.

I should have recognized that. I looked right at it and thought they were selecting by the form Alias. No one ever accused me of being smart.

Another blunder on my part is that the lines:

Call item.copyitemtodocument(destnote, Firstname)

are missing a set of quotes. they should be:

Call item.copyitemtodocument(destnote, “Firstname”)