Showing posts with label debugging. Show all posts
Showing posts with label debugging. Show all posts

Thursday, December 2, 2010

Debugging traditional WebQueryOpen/WebQuerySave code

I just had a eureka moment when it comes to debugging WQO/WQS code. Once upon a time I decided it was impossible to debug code that required NotesSession.DocumentContext, through the (local) Domino Debugger. It's not :)

You need a global NotesDocument variable that you can bind the DocumentContext to. The reason that it has to be global is that it has probably has to be available across multiple methods/scopes. It should be put inside a script library that doesn't use other script libraries. In most of my apps, I have a script library stack, where the most general code is put inside a script library that most other script libraries use (either through "inheritance" or through Use). This is where I put the global declarations.

Then you need a function that returns either NotesSession.DocumentContext, or a temporary document. This should be put inside the same script library as the aforementioned global declaration.
Function getDocumentContext() As NotesDocument
On Error GoTo returnEmptyDocument
'// Returns NotesSession.DocumentContext if availabe, else a temporary document
Dim s As New NotesSession()
Set getDocumentContext = s.documentContext
If getDocumentContext Is Nothing Then GoTo returnEmptyDocument

Exit Function
returnEmptyDocument:
If contextDoc Is Nothing Then Set contextDoc = s.currentDatabase.createDocument()
Set getDocumentContext = contextDoc
Exit Function
End Function
contextDoc is declared as a global variable.

Wherever in your code where you fetch NotesDocument.DocumentContext, you have to change that to call the above function, getDocumentContext().

To test code, all you have to do is to create an agent, bind getDocumentContext to a NotesDocument variable (or modify the global var), set the needed fields, and you're ready to debug the code.

E.g.
Call getDocumentContext()
Call contextDoc.replaceItemValue( "someNeededField", "someTestValue" )
Call methodThatsDesignedForWQOOrWQS()
Share and enjoy!

Wednesday, October 27, 2010

XPages: New methods to the Debug class

I added couple of new methods to the Debug class.

Debug.messageToPage( message:String ): Adds a message to the bottom of the page.
Example usage:
..
Debug.messageToPage( viewScope.someValue )
..
Debug.exceptionToPage( exception:String ): Adds exception message to the bottom of the page
Example usage:
function someFunction(){
try {
..
} catch( exception ){ Debug.exceptionToPage( exception ) }
}
Each call to the function results in a line being added to the "message box". The code for the Debug class can be found here.

The messages are displayed in a "validation error" type box (xspMessage).

I would think messageToPage is the most useful, as an exception may crash the entire page/the message box won't be rendered.

Share and enjoy!

Wednesday, December 12, 2007

Debugging: Inspect what's being posted from a form

Sometimes I make parts of a form using PassThruHTML/hidden notes-fields. Mostly because Domino-generated HTML is hard to style (especially radio-buttons/checkboxes). This sometimes work immediately, and sometimes it takes hours to make it work. I've found it a great help to see what is being posted to the server.

There are HTTP-sniffer applications that you can inspect the request with, but I find it easier to post the form to an agent, and then print the request-content as a HTML-table.

Example of output, Jake's FakeNames database, Person-form with a couple of fields filled in.

It's also handy to "echo" get-requests when developing agents: A simple ?OpenAgent

In the demo-application for this blogpost, I've made a (javascript) action-button that rewrites the action-field in the form to point to an agent. The agent tries to print every field in NotesSession.DocumentContext.

To make this work in your applications, (hopefully,) you only have to copy the Script Library, InspectRequest, the agent inspectrequest, and the shared action, Inspect current form-values. Insert the shared action into the form you want to test.

To inspect DocumentContext in other agents, use docToHTML in the Script Library, InspectRequest. As a rare occurence, I've actually documented this function.

To get the current field-values, I trigger the equivalent of @Command( [ViewRefreshFields] ), using the Domino _doClick function.

>> Download demo application