First of all my lotusscript knowledge isn’t that good. I’m just editing an existing script
I’m having problems with a lotusscript code. This should import only a textline in a field (this is working) but it should also check if the text link already exists (I can’t get it working)
This is what I thought the script should be for checking if description already exist (It just a part of the wholde script)
I didn’t know it it was allowed to add whole script to the website, so here it is.
I don’t get an errormessage. When I run it twice a new document with same description appears in the database.
Sub Importadresses
Dim s As New notessession
Dim db As notesdatabase
Dim view As notesview
Dim dc As notesdocumentcollection
Dim doc, NewInvoiceDoc As notesdocument
Const Formule= "@Unique"
fileNum% = Freefile()
fileName$ = "c:\tmp\upload.txt"
Print "Importing Adresses... "
Set db = s.currentdatabase
Set view = db.GetView("(Ipnumber2)")
Open fileName$ For Input As fileNum%
Do While Not Eof(fileNum%)
Line Input #fileNum%, regel$
If regel$="" Then Exit Do
lengte = Len(regel$)
pos = Instr(regel$, Chr(34))
Description = Trim(Left(regel$, pos - 1))
regel$ = Right(regel$, lengte - pos)
'check if document already exists:
Set dc = view.GetAllDocumentsByKey(Description)
Set doc = dc.GetFirstDocument
Do While Not doc Is Nothing
If (NewInvoiceDoc.IpNumber = Description) Then
'mark for deletion
doc.DeleteRemark = "True"
Call doc.save(True,True)
Set doc = dc.getnextdocument(doc)
Else
Set doc = dc.getnextdocument(doc)
End If
Loop
'new document
Set NewInvoiceDoc = New NotesDocument(db)
NewInvoiceDoc.Form = "klant"
NewInvoiceDoc.IpNumber = Description
NewInvoiceDoc.aantal = 0
NewInvoiceDoc.status = "e-maillist active"
Call NewInvoiceDoc.save(True,True)
Loop
'delete marked documents
selection$ = "Form = ""klant"" & DeleteRemark = ""True"" "
Set dc = db.Search(selection$, Nothing, 0)
Call dc.Removeall(True)
Print "Ready Importing Adresses."
If (NewInvoiceDoc.IpNumber = Description) Then
'mark for deletion
You can’t do a comparison like the line in bold. You’re comparing the contents of a string variable (Description) with the complete contents of a NotesDocument field (NewInvoiceDoc.lpNumber). If the doc field is a single value then this will be OK:
If(NewInvoiceDoc.lpNumber(0) = Description)
This is because NotesDocument.FIELDNAME(0) will return the first value of a field as a string (NotesDocument.FIELDNAME(1) will return the second, and so on). When you assign the fields / values later on, that’s OK.
I would also change this bit (unrelated, and not a part that’s “broken” but just 'cause I’m anal) from this:
Do While Not doc Is Nothing
[...]
doc.DeleteRemark = "True"
Call doc.save(True,True)
Set doc = dc.getnextdocument(doc)
Else
Set doc = dc.getnextdocument(doc)
End If
Loop
To this:
Do While Not doc Is Nothing
[...]
doc.DeleteRemark = "True"
Call doc.save(True,True)
End If
Set doc = dc.getnextdocument(doc)
Loop
It just flows better, and you don’t need to repeat the GetNextDocument directive.