Lotus Script agent runs fine in WebQuerySave but not QuerySave

Guys I am royally stumped here and any help would be very appreciated.

I have a form that collects some stuff about a project. It then usese this agent upon saving to retrieve a project number an dupdate the project counter.

The form is dually accessed both over the web and over the notes client.

For the web I call the agent in the web query save. It runs fine and does everythign it should.

For notes I call it in the Querysave event - again - calls the same exact agent, same form, same everythign bit for whatever reason, it still saves the document when ran throught he notes client, but I get an @Error where the project number should be.

Now my experience has been that things work in notes and not the web especially script but this time, its not working in notes. Also the code thiny at the bottom that usually tells you there is a script error or whatever gives me no errors.

Here is the actual Agent code.

Again works when executed over the web (fires off on web query save and the save method is via a javascript button that does javascript input validation adn then calls a do submit)

Does not work when done over Lotus Notes - action save button for which the code is :

@If(@Command([FileSave]);@Command([FileCloseWindow]);@Return(“”))

(not sure why it has all that extra crap in the save button - I inherited this app).

the script::::

Declarations:

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim profileStrings As NotesItem

INitialize code:::

Sub Initialize

On Error Goto errorHandler



Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim profdoc As NotesDocument

Dim profileStrings As NotesItem

Dim countdoc As NotesDocument

Dim view As NotesView

Set db = session.CurrentDatabase

Set doc=session.DocumentContext



'doc.projmgmt_1=doc.projmgmt_1(0)+doc.projmgmt_1_1(0)

'doc.projmgmt_2=doc.projmgmt(0)-doc.projmgmt_1

'doc.projmgmt_1_1=0



If doc.count(0) = "" Then

	

	Set view=db.GetView("count")

	Set countdoc = view.getfirstdocument

	'Set doc = db.GetProfileDocument("Counter")

	stringval = countdoc.count(0)

	countdoc.count = countdoc.count(0) + 1

	Call countdoc.Save(True,True)

	doc.count = Cstr(stringval)

	

	success = doc.COMPUTEWITHFORM(False, False)

	

	If success Then

		Call doc.save(True, True)

	End If

End If





Exit Sub

errorHandler:

Print "Error #" & Format$(Err) & " at line " & Format$(Erl) & ": " & Error$, 0, "Error"  

End Sub

TIA script gurus

Subject: RE: Lotus Script agent runs fine in WebQuerySave but not QuerySave

I posted this earlier, but I don’t know if you saw it…


Can’t say for sure, but your problem might be here:

“Set view=db.GetView(“count”)”

“Set countdoc = view.getfirstdocument”

It’s always a good idea to make sure you have a document before trying to use it. It doesn’t appear that your doing this.

Maybe if you change that last line to say:

If doc.count(0) = “” Then Set view=db.GetView(“count”)

Set countdoc = view.getfirstdocument

If Not(countdoc is Nothing) Then

'Set doc = db.GetProfileDocument(“Counter”)

stringval = countdoc.count(0)

countdoc.count = countdoc.count(0) + 1

Call countdoc.Save(True,True)

doc.count = Cstr(stringval)

success = doc.COMPUTEWITHFORM(False, False)

   If success Then

      Call doc.save(True, True)

   End If

End If

Hope this helps.

J.G.

Subject: RE: Lotus Script agent runs fine in WebQuerySave but not QuerySave

I realize this is way after the fact, but thought I would post it in case someone else comes across this problem.

I thought I would save myself some time and re-use a WebQuerySave agent for a QuerySave in a Web DB that I am retro-fitting to be usable in the Notes client as well. Remember that when you call a LotusScript agent from the QuerySave event, you need to set the notesdocument from the notesuidocument instead of the session documentcontext. I found that the uidoc.document overwrote my agent changes to the session.documentcontext.

So instead of:

Dim s as new notessession

Dim doc as notesdocument

Set doc=s.documentcontext

You should have:

Dim ws As New notesuiworkspace

Dim uiDoc As notesuidocument



Dim doc As notesdocument

Set uiDoc=ws.currentdocument

Set doc=uiDoc.document

If you are using the same agent for both a QuerySave and a WebQuerySave, you will need an IF statement for client type when setting up the notesdocument variable. Not hard, but just something you forget about if you don’t often have a combined DB.

Hope this saves someone else the hassle and frustration.

Subject: Lotus Script agent runs fine in WebQuerySave but not QuerySave

“All that extra crap in the save button” is there to prevent the Save Options dialog from popping up when field validation fails. Without the @If, the [FileSave] call will always be followed by a [FileCloseWindow], and if validation has failed, there will be unsaved changes on the UI document, so the user will see “Do you want to save your changes?”

And session.DocumentContext is the “current document” object on the web. In the Notes client during the QuerySave, the equivalent object would be NotesUIWorkspace.CurrentDocument.Document (or Source.Document, if you use the provided UI document object).