I am trying to do a simple agent that checks to see if a document has a certain value, and if it does, proceeds to refresh it. Unfortunately i get a type mismatch error at ‘If doc.Product=“apollo” Then’ line. Product is a text field in the doc. Is this not an acceptable way to refer to a field in a doc? what is the right way?
Sub Initialize
Dim Session As New NotesSession
Dim db As NotesDatabase
Set db = session.currentdatabase
Dim doc As NotesDocument
Dim view As NotesView
Dim HDA_Product As String
Set view = db.GetView("Refresh")
If view Is Nothing Then Exit Sub
Set doc =view.getfirstdocument
While Not doc Is Nothing
If doc.Product="apollo" Then
With doc
.ComputeWithForm False, False
.save True, False, True
Set doc = view.getNextDocument(doc)
End With
End If
Wend
End Sub
Thanks!
(and why doesn’t the lotus help in designer allow you to search for “Field”?!)
Items (the back-end object behind a field) always* contain arrays of values, even if the array only has one member. Your code needs to take that into account:
If doc.FieldName(0) = scalarValue Then
Note, though, that this syntax is vulnerable, since the script interpreter/compiler has no way of determining whether you intend to address an Item or a “proper” property of the document. For instance, a property called “Lock” was added to the NotesDocument class in Notes and Domino 6, so code that used the extended class syntax to address a field named “Lock”, and which would compile properly in R5 and previous versions, could not be compiled in Designer 6 or later. Using the complete syntax is unambiguous and will avoid potential problems:
If doc.GetItemValue(“FieldName”)(0) = scalarValue Then
*There is a condition where an Item will contain an error rather than any normal value. Errors (such as the error returned by a bad @DbLookup) are not arrays, but cannot be compared to regular scalar values either, so a LotusScript error will occur whether you use the (0) or not.