Unable to create new records in other database using local form (writing background agent)

pts.
Tags:
Database
IBM DB2
LotusScript
Oracle
Hi, I am trying to create an agent in a database that creates a new document in the local address book using its local form (Person). Debug shows that all is fine except that it does not save (the flag value is -1). What am I missing? Here is my code: Sub Initialize Dim s As NotesSession Dim sourcedb As NotesDatabase Dim destdb As NotesDatabase Dim sourcedoc As NotesDocument Dim destdoc As NotesDocument Dim documents As NotesDocumentCollection Dim success As Variant Set s = New NotesSession Set sourcedb = s.CurrentDatabase Set destdb = New NotesDatabase("", "names.nsf") Set documents = sourcedb.UnprocessedDocuments For n = 1 To documents.Count Set sourcedoc = documents.GetNthDocument(n) Set destdoc = destdb.CreateDocument destdoc.Form = "Person" ' Copy each field we need from the old form, to the new form. destdoc.Field1= sourcedoc.Field1 destdoc.Field2 = sourcedoc.Field2 success = destdoc.Save(True,True) Next n End Sub

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hi Arnaud,

if the success flag is being set to -1, then that means True, ie it has saved successfully. Maybe you think it’s not being saved because it’s not appearing in your Contacts view? If you look at the selection formula for that view, it’s looking for a field called ‘Type’ set to ‘Person’. So try setting that field as well, and you should be ok.

btw, stay away from GetnthDocument if you’re processing a large number of documents. It has a major performance hit – the further you get into the collection, the slower it goes. Go with this kind of thing:

dim documents as NotesDocumentCollection
dim sourcedoc as NotesDocument
‘set the value of documents
set sourcedoc = documents.GetFirstDocument
do while not sourcedoc is nothing
‘do your processing here
set sourcedoc = coll.GetNextDocument(sourcedoc)
loop

hth

Tony

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following