Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Agent to modify Author fields on docs from view

Status
Not open for further replies.

DoctorGonzo

Programmer
Jan 23, 2004
48
GB
Hi All,

I am trying to write an agent which runs on a selected document in a view.

When run, it will modify two readers fields on the document and then save.

Here is what I have up to now, but I am having trouble getting a handle to the document I wish to modify, and the help is a little hard for me to understand! Just need pointing in the right direction!

Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Dim view As NotesView
Set view = db.GetView("Alldocs")

*** THIS IS THE BIT WHERE I WANT TO SELECT THE DOC :
I know there's no such thing as getcurrentdocument, but wanted to give you the idea...

Dim doc As NotesDocument
Set doc = view.getcurrentdocument

Dim firstreaders As notesitem
Set firstreaders = doc.getfirstitem("FirstReaders")
firstreaders.IsReaders = True

Dim secondreaders As notesitem
Set secondreaders = doc.getfirstitem("secondReaders")
secondreaders.IsReaders = True

*** DO I NEED A doc.save here?

End Sub

Many thanks guys,

Gonzo
 
You cannot get the handle in the view object. You need to use the NotesUIDatabase object to collect selected documents in a view.

Example :
Code:
dim ws as new notesuiworkspace
dim uidb as notesuidatabase
dim coll as notesdocumentcollection
dim doc as notesdocument
(...)

set uidb=ws.currentdatabase
set coll=uidb.documents
if coll.count>0 then
    set doc=coll.getfirstdocument
    do while not(doc is nothing)
        (...)
    loop
end if

And yes, you do need to save a notesdocument object if you modify item values in it, otherwise when you go to the next object, the changes will be lost.

Have fun !

Pascal.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top