Hi.I’m new to Domino Designer so the following problem may be elementary.
I’ve written some LotusScript code to count the number of documents in a view and then extract the data from a couple of fields from a randomly selected document.
The code seems to be counting the docs okay, and walking the view to pick up field info from the random document.
But I’ve put in an If statement to try to get the program to look for another random document if one or both of the two fields on the random doc are empty.
This doesn’t seem to work - the code is still sometimes returning empty fields as its results.
Here is the code:
Sub Click(Source As Button)
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim s As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim docTotal As Long
Dim docNo As Long
Dim randDocNo As Long
Dim randChemForm As String
Dim randCASNo As String
Dim randProdName As String
Set db = s.CurrentDatabase
Set view = db.getView("PN")
REM Count number of documents in View
docTotal = view.EntryCount
REM Display result of document count
Msgbox "Total number of documents = " & docTotal, , "Document Count"
REM Generate random number between 1 and the total number of docs
randDocNo = ((Rnd()*(docTotal-1))+1)
REM Display random document number
Msgbox "Number of randomly selected document = " & randDocNo, , "Random Document Number"
REM Walk through view to find document
Set doc = view.GetFirstDocument
docNo = 1
randChemForm = ""
randCASNo = ""
Do While docNo<>randDocNo
randChemForm = doc.GetItemValue("Prod_ChemForm")(0)
randCASNo = doc.GetItemValue("Prod_CASNo")(0)
If docNo = randDocNo Then
If randChemForm = "" Or randCASNo = "" Then
randDocNo = ((Rnd()*(docTotal-1))+1)
Msgbox "Number of randomly selected document = " & randDocNo, , "Random Document Number"
docNo = 0
Set doc = view.getFirstDocument
End If
End If
docNo = docNo + 1
Set doc = view.GetNextDocument(doc)
Loop
Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
doc.Rand_ChemForm = randChemForm
doc.Rand_CASNo = randCASNo
End Sub
Any ideas? Thanks.