Cannot set fields on browser form with WebQueryOpen agent

I got a function with lotus script codes to calculate the 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 client. Both field got values I want:

Sub Postopen(Source As Notesuidocument)

If source.EditMode Then

Dim doc As NotesDocument

Set doc = Source.Document

doc.FieldA = fCalculate

Call doc.Refresh

End If

End Sub

However, when I cater the browser side, I add an agent to call the function from WebQueryOpen, the agent simply call the function and then set the values:

Agent:

Sub Initialize

Dim session As New NotesSession

Dim doc As NotesDocument

Set doc = session.DocumentContext

If doc.EditMode Then

doc.FieldA = fCalculate

Call doc.Refresh

End If

End Sub

The result is that both fields are empty,

I try to remove Editmode and Refresh lines since I know that EditMode and Refresh only applies to uidoc, but still nothing change, anyway what should I to deal with Editmode and Refresh?

Hope sombody shed some light on me.

Subject: Cannot set fields on browser form with WebQueryOpen agent

We will not be able to figure out the error unless we have a look at your fcalculate function…

Also doc.EditMode and doc.refresh wont work…

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?

Subject: RE: Cannot set fields on browser form with WebQueryOpen agent

I figure out what happens.

I do a little experiment by adding a button to call this agent.

In fact the agent could be called but as I forget that under agent, username refers to server name, so this statement:

staff = session.UserName

could not return the actual Webuser’s name so it cannot enter the loop and thus nothing happens.

Then I change the Agent properties by checking the box to run as Web User, but still nothing happens.

I further check the box of running agent on behalf of me (Administrator), and still nothing happens.

I test by hardcoding staff=“WebuserXXX” and finally get what I want.

So questions:

(1) Why can’t session.username return webuser’s name even I check the agent property box to run as Web user? (or if it really could, it should have the right to run after I check the box to run on behalf of me/administrator?

(2) It seems that agent called from WebQueryOpen cannot display print statement so I have difficulty on debugging. (I can’t use remote debugging since I don’t wanna bother Notes Admin to do a list of tasks for the set up 8-<

(3) How can I check if the doc is in editmode on browser (using lotus script) like in uidoc? I cannot use:

If doc.Editmode

…

(4) How to refresh fields of the doc on browser (using lotus script) like in uidoc? I cannot use:

Call doc.Refresh

Many Thanks!!

Subject: RE: Cannot set fields on browser form with WebQueryOpen agent

Hi,

(1) We cannot use Session.Username since this returns the name of the server…this is bcoz the agent runs on the server…create a computed for display field and give the formula as @username…use this field in the web query open agent…

(2) For debuging create error handlers in the agent and log the erros in the Agent log …

(3) To check whether the doc is in edit mode create Computed for Display with formula @isDocumentbeingEdited and use this field for checking the edit mode…FYI…we neendn’t check for EditMode in webqueryopen agent for assigninig field values…

(4) We dont need refresh in web query open agent …

Subject: RE: Cannot set fields on browser form with WebQueryOpen agent

May I know more…(1) I found that we can use Session.EffectiveUserName by checking the box on run as web user. That solves the problem

(2) That will be great, I better study how to use Agent log …

(3) I just wonder if I open an exiting document on web, if there is no need to check edit mode, the script will always run and the fields get set even in read mode? Actually I just want to set the values when I create or edit the document.

Thanks in advance.