Subject: RE: Cannot set fields on browser form with WebQueryOpen agent
Thanks Pravin, let me describe in details as below:
The function (fGetList, see below) is to generate a list of values on field A.
Another field B (combobox) populates the options using field A.
I call the function from PostOpen and the script is run ok on Notes client. Both field A & B got values I want:
Sub Postopen(Source As Notesuidocument)
If source.EditMode Then
Dim doc As NotesDocument
Set doc = Source.Document
doc.FieldA = fGetList
Call doc.Refresh
End If
End Sub
However, when I cater for browser, I need to call an agent from WebQueryOpen:
(@Command([ToolsRunMacro]; “aGetList”)
The agent simply call the function (fGetList) and then set the values:
Agent aGetList:
Sub Initialize
Dim session As New NotesSession
Dim doc As NotesDocument
Set doc = session.DocumentContext
If doc.EditMode Then
doc.FieldA = fGetList
Call doc.Refresh
End If
End Sub
The result is that both fields are empty,
as I know that EditMode and Refresh only applies to uidoc, so I remove the condition to check doc.EditMode and clear doc.Refresh, but still nothing appears on the fields,
I am sure the function is ok since it could generate values when called under client side:
Function fGetList As Variant
Dim ReturnArray() As String
Dim session As New NotesSession
Dim db As NotesDatabase
Dim db2 As NotesDatabase
Dim viewS As NotesView
Dim viewH As NotesView
Dim docS As NotesDocument
Dim docH As NotesDocument
Dim db2Name As String
Dim staff As String
Dim headkey As String
Set db = session.CurrentDatabase
db2Name = "test02.nsf"
Set db2 = session.GetDatabase( db.Server, db2Name)
Set viewS = db2.GetView( "vStaff" )
Set viewH = db2.GetView( "vHead" )
staff = session.UserName
i = 1
Set docS = viewS.GetFirstDocument
While Not(docS Is Nothing)
Set docS = viewS.GetDocumentByKey(staff, True)
If docS Is Nothing Then
fGetList = ReturnArray
Exit Function
End If
Redim Preserve ReturnArray(i) As String
ReturnArray(i) = docS.HeadPost(0)
headkey = ReturnArray(i)
Set docH = viewH.GetDocumentByKey(headkey, True)
If docH Is Nothing Then
fGetList = ReturnArray
Exit Function
End If
staff = docH.HeadName(0)
i = i + 1
Wend
fGetList = ReturnArray
End Function
Any hint?