Subject: RE: Replace missing values in a view, ReplaceItemValue is not working
As far as I know the method getItemValue always return a value. If the field does not exists => return value is an empty string.
So your statement isNull(div) is never true.
Also I don’t see how the forall loop can be useful except if your field Division is a richtext field. So if it’s not a richtext get rid of the forall loop.
So if you want to add the value 122 in the field division does not exist just test if the getItemValue is equal to an empty string.
Last thing with the line if doc.hasItem(“Division”), if the doc does not have a field Division, it won’t be set with the new value.
As Arshad said put the doc save inside the if statement to save the change for each doc.
Here is a modified code which should work
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
dim fieldValue as String
Set db = session.CurrentDatabase
Set view = db.GetView(“Test”)
Set doc = view.GetFirstDocument
While Not(doc Is Nothing)
fieldValue=doc.GetItemValue(“Division”)(0)
If fieldValue=“” Then
call doc.ReplaceItemValue ( “Division”, 122 )
Call doc.Save( True, True )
End If
Set doc = view.GetNextDocument(doc)
Wend
Renaud