Q

Agent that increments a field in the latest doc in a view

Hi, I need to write an agent that increments a field in the latest document in a view. The view is categorized by name. The agent is supposed to get the latest document for each person and increment a field called LeaveDays. This agent will run on schedule once a month. How can I do this?
You need to get a handle on the successive documents in the view. If the name of the next document is not the same, then you process the current document. Some sample code might look like this.
Sub Initialize
 Dim session As New NotesSession
 Dim db As NotesDatabase
 Dim docThis As NotesDocument
 Dim docNext As NotesDocument
 Dim view As NotesView  
 Dim item As NotesItem
 Dim itemName As NotesItem
 Dim strName As String
 Dim varProcess As Variant
 
 Set db = session.Currentdatabase
 Set view = db.Getview("your view name") 
 
 Set docThis = View.getFirstDocument()
 strName =docThis.Name(0)
 
 While Not (docThis Is Nothing)
  varProcess = False
  Set docNext = View.getNextDocument(docThis)
  If (docNext Is Nothing) Then
   'last document in view
   varProcess = True
  Elseif (docNext.Name(0) = strName) Then
   'do Nothing
   varProcess = False 
  Else
   'this is the last document for this person
   varProcess = True
  End If
  If varProcess Then
   'process the leaveDays field - add your code
   
   'set the name to the next person
   strName = docNext.Name(0)
  End If 
  
  Set docThis = docNext
 Wend
End Sub

Do you have comments on this Ask the Expert Q&A? Let us know.

Dig Deeper on Lotus Notes Domino Agents

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close