hcl-bot
November 30, 2005, 9:13am
1
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.
hcl-bot
November 30, 2005, 9:32am
2
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
hcl-bot
December 1, 2005, 11:04am
4
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
hcl-bot
December 5, 2005, 11:06am
5
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