How to create a document for each document in existence

I’m using notes to keep track of properties that we manage.I have a main form called “Property Card”.

There is one of these Form for each property that we manage.

Every month we are expected to do a drive by inspection on each property.

I’d like to create an agent or action that will create an “inspection” form for each “property card” that exists each month.

Additionally I’d like the new inspections cards to be stamped with the month the inspections are to occur.

I’m looking for some code that will cycle though the Property cards, and in turn generate the inspection cards with relevant data from the property card.

I’m mot treating the inspection cards as a response at this time.

Right now there is an action button on the property card to create an inspection, but I can only generate one at a time this way.

We have over 180 properties…

I was imagining hitting a button,

a dialog pops up where a month is selected.

Then a “Inspection” is created for each card populated with that month listed as “inspection for: ”, and other relavent information like the address.

I’m guessing the code should open each property card in turn and generate the inspection while the target property is the focus. I know how to design the form so that it captures this pertanent information.

I don’t know how to cylcle though the propertiy cards, and create the inspections.

Any help getting started would be appreciated

I realize this might be two big a question to ask in this forum.

Hopefully somebody can get me started and I can work the problem a step at a time.

Jim Lamb

Subject: How to create a document for each document in existence

You can write a lotus script agent and schedule it.

Create a flag field in the form. Let’s say “InspectionFlag”.

Add this flag in the view selection formula so that, this view contains only documents which are not having the inspection flag. Something like that as per your requirement. I guess you create the inspection document only once right? If not no need to use this flal at all. Every month, the scheduled agent will run on all and create inspection documents for all.

Dim s as New notesSession

dim db as NotesDatabase

dim v as NotesView

dim vc as NotesViewEntryCollection

dim e as NotesViewEntry

dim doc as NotesDocument

dim inspdoc as NotesDocument

set db = s.Currentdatabase

set v = db.GetView(“Your View”)

set vc = v.Allentries

Set e = vc.GetfirstEntry()

'Loop thru the documents of the view

do until e is nothing

set doc = e.Document

'Checks the inspection flag whether created

the inspection document for that main doc.

If not creates one.

if doc.InspectionFlag(0) <> “Y” then

set inspdoc = db.CreateDocument

inspdoc.Form = "Your inspection form"

inspdoc.Field = doc.YourField(0) for single value field

inspdoc.Field = doc.YourField for multivalue field

Call inspdoc.save(True, true) 

 'Set the flag in main document and save it.

 doc.InspectionFlag = "Y"

 Call doc.Save(True, true)

end if

set e = vc.GetNextEntry(e)

Loop

Just go thru the help of these properties and methods used here so that you may have good idea to use as per your requirement.

Subject: RE: How to create a document for each document in existence

Thank you so much!

I think that will definitely get me started.

Jim Lamb