Problem solve Get help with specific problems with your technologies, process and projects.

Making an agent that would randomly select 5% of the docs from a specified view and send them a note

I am looking to design an agent (scheduled or manual) to randomly select 5% of the docs from a specified view and send a note to the Send To field in each doc in the random selection. I would appreciate any help you can give me.
Does it need to be exactly 5%, or do you just want a 1 in 20 chance of sending a message for each document there, which will give you roughly 5%, but maybe more or less?

The reason I ask is that the latter is much simpler; you can write an agent that runs on all documents:

SELECT @Random < 0.05 & (selection formula from the view);
@MailSend(SendTo; ""; ""; "subject line"; "message body"; ""; [IncludeDocLink])
If you need to send to exactly 5% of the entries, then you probably have to write it in LotusScript -- read the view, repeatedly select a document at random, send to them and remember which documents you already did to prevent doing the same one twice. For example:
Dim ses As New NotesSession
Dim view As NotesView
Dim db As NotesDatabase
Set db = ses.CurrentDatabase
Set view = db.GetView("($Inbox)")
Dim entries As NotesViewEntryCollection, anEntry As NotesViewEntry
Dim count As Long, remaining As Long, pos As Long
Dim noteid As String
Dim alreadysent List As Integer
Dim doc As NotesDocument

Set entries = view.AllEntries
count = entries.Count
remaining = count/20 ' 5% of entries in the view.
Print "count = " & count & ", remaining = " & remaining
While remaining > 0
remaining = remaining - 1
pos = Rnd() * count + 1
Set anEntry = entries.GetNthEntry(pos)
' as long as we already processed this document, choose a different document.
While Iselement(alreadysent(anEntry.NoteID))
pos = Rnd() * count + 1
Set anEntry = entries.GetNthEntry(pos)
alreadysent(anEntry.NoteID) = 0 ' don't do this document again.
Set doc = db.GetDocumentByID(anEntry.NoteID)
SendNotice doc

The SendNotice function is the one that would actually send your e-mail -- you can see how to do this in the examples of the Send method.

Dig Deeper on Domino Resources - Part 7

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • 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 ...