Multiple values/multiple docs

Hi,

I’m looking for a code which would create multiple documents for all values in 1 field.

Here’s the idea: a booking form to book resources. The resource field allows multiple values. All other fields allow just 1 value.

When clicking save&close, multiple docs need to be created for each value in the resource field and all other fields should be available on all these docs.

Any ideas?

Thanks,

B.

Subject: multiple values/multiple docs

Hi,

Look at this old post from Forum 4 & 5, it helped me well! :

https://www-10.lotus.com/ldd/46dom.nsf/55c38d716d632d9b8525689b005ba1c0/f4cd718a0f5a0cd385256a4f0050f82b?OpenDocument&Highlight=0,multiple,document%20,ceretto

It was for the Web but you can adapt it…

HTH

Thierry

Subject: RE: multiple values/multiple docs

Hi,

Thanks for the info. I’ve tried the code but I seem to get stuck at the 'Set your field values here part. I’ve tried a series of things, but it doesn’t seem to like it.

The field containing the multiple values is linked to the address book and thus can contain any name within our addressbook.

Any help would be greatly appreciated.

B.

Sub Initialize

Dim session as New NotesSession

dim db as NotesDatabase

Dim webDoc as NotesDocument

dim newDoc as NotesDocument

dim nItem as NotesItem

Set db = session.CurrentDatabase

Set webDoc = session.DocumentContext

set nItem = webDoc.GetFirstItem( “FieldName” )

Forall val in nItem.values

set newDoc = New NotesDocument( db )

'Set your field values here

Call newDoc.Save( False, True )

End Forall

Exit Sub

End Sub

Subject: RE: multiple values/multiple docs

Hi,

An example :

Dim session as New NotesSession

dim db as NotesDatabase

Dim webDoc as NotesDocument

dim newDoc as NotesDocument

dim nItem as NotesItem Set db = session.CurrentDatabase

Set webDoc = session.DocumentContext

set nItem = webDoc.GetFirstItem( “AdrBookNames” )

Forall val in nItem.values

set newDoc = New NotesDocument( db )

'Set your field values here

'Set the form

newDoc.Form = “Test”

'Put “val” value in field, let’s say, “ABName”

newDoc.ABName = val

'Save the document

Call newDoc.Save( False, True )

End Forall

Exit Sub

End Sub

Thus for each value of “AdrBookNames” a document is created with form “Test”, example :

“AdrBookNames” contains 6 values : John DOE, John LENNON, Peter GABRIEL, Gino VANELLI, Linda RONDSTADT, David Lee ROTH

The script will create 6 documents, each document will contain ONE value…

Make sense?

Thierry

Subject: RE: multiple values/multiple docs

Figured out how to do it. Thanks.One more thing, would it also be possible to have the newDoc in a different database?

Your help is much appreciated.

B.

Subject: RE: multiple values/multiple docs

Hi,

“…would it also be possible to have the newDoc in a different database?..”

Yes, but you must declare the database and the code (agent?) must have the right to create document in this database.

In example below I call it "targetDb " :

Dim session as New NotesSession

dim db as NotesDatabase

'***** Target database

dim targetDb as NotesDatatbase

'*****

Dim webDoc as NotesDocument

dim newDoc as NotesDocument

dim nItem as NotesItem

Set db = session.CurrentDatabase

'***** Target database

Set targetDb = New NotesDatabase( server$, dbfile$ )

'*****

Set webDoc = session.DocumentContext

set nItem = webDoc.GetFirstItem( “AdrBookNames” )

'Document is created in target database

set newDoc = New NotesDocument( targetDb )

HTH

Thierry