trying to figure out the best way to go about this. Have an Inventory database, as of now it has about 1,000 documents for hardware items.
I want to write an agent to find duplicate Serial Numbers. Now I know how to do it by lotusscript; by opening each document grabbing the value, then getNextDocument, get that value and then compare it. Seems like overkill to open everydocument for one value.
My real question is, is this the best way to do this? Is it easier or better to use another method, such as viewEntrys or something else that I am just not really aware of. Looking through help now but my understanding of the helps wording does not always work in my favor.
Only other thing, is once I find a duplicate value I would like to pull up some other values.
If my original way is best thats fine, but I know more often than not there are better ways to do things than what I know.
I did this a while back, here is the function I used:
Sub ActionSearchDoubleNumber
Dim view As notesview
Dim doc As notesdocument
Dim aNumber() As String
On Error Goto errorHandling
Set view = s.currentdatabase.getview( "YourViewSortedByNumber" )
Set doc = view.getfirstdocument
i% = 0
Do
thisNumber$ = doc.columnvalues(0)
Set doc = view.getnextdocument( doc )
If doc Is Nothing Then Exit Do
nextNumber$ = doc.columnvalues(0)
If thisNumber$ = nextNumber$ Then
Redim Preserve aNumber(i%)
aNumber(i%) = thisNumber$
i% = i% + 1
End If
Loop
If i% = 0 Then
Msgbox "No double numbers found."
Exit Sub
End If
[snip]
Exit Sub
errorHandling:
Print Cstr(Err) & " " & Error$
Resume Next
End Sub
s (NotesSession) is global within the script libaray.
Get the documents to loop through (one of a number of methods).
Build a view of docs sorted by serial number and then use getAllDocumentsByKey(key, TRUE) to get a collection of matching documents. Do this in a Do loop. Don’t use getnthdocument to move on - use getnextdocument If collection.count>1 you know you have a match.
Watch out for leading /trailing spaces and case issues. Suggest @uppercase@trim the serial number in the view column and similar in script when geting the serial to use as a key.