ChadSmiley Blog Things about family, life, coding, and more

14Jun/063

Session.DocumentContext something isn't right

If you ran the following code in the Web Query Save agent that was assigned to a form with a subject field. The original value of subject was "Truck" and the new value entered on the web was "Car". The Web Query Save agent code was:

Dim Session As New NotesSession
Dim docBefore As NotesDocument
Dim documentContext As NotesDocument
Dim docAfter As NotesDocument

Set docBefore = Session.CurrentDatabase.getDocumentByUNID( "f02506889e2d5cfc8625712f001b02f9" )
Msgbox "Before: " +
docBefore.subject(0) Set documentContext = Session.DocumentContext
Msgbox "Context: " + documentContext.subject(0)
Set docAfter = Session.CurrentDatabase.getDocumentByUNID( "f02506889e2d5cfc8625712f001b02f9" )
Msgbox "After:" +
docAfter.subject(0)

I was expecting to see:
Before: Truck
Context: Car
After: Truck

What I saw was:
Before: Truck
Context: Car
After: Truck

Domino seems to read the document from the database until the DocumentContext is used at which the document is read from memory where the changes are allready made. This will make my job capturing what has change for Open Audit a litte hard, thus take a little more time.

Comments (3) Trackbacks (0)
  1. I went through a similar thing when writing the agent in the TriggerHappy database that captures changes to a document (can’t remember what the agent is called, but I think it’s the only one in there).

    http://www.openntf.org/Projects/pmt.nsf/ProjectHome?ReadForm&Query=Trigger%20Happy

    I seem to remember that it had something to do with calling Delete on the in-memory document before retrieving the on-disc document.

  2. Great memory Julian, yes calling the delete and then loading it again is the hack. When you said to look at TriggerHappy to see what you did for document logging I was not looking for this.

    Thanks, you made my day.

  3. Realise you got an answer to this but I have also seen similar behaviour in a different context (and under R5)

    Same problem – once a document was loaded in memory getDocumentByID would return the in-memory document. Even deleting the document wasn’t enough.

    What we did was delete the document, delete the view from which we got the document then get the view again, then get the document again from the view.

    This ensured that we got the document from disk rather than the in-memory document.

    The code still runs under R6.5 but I haven’t tested the problem there.

    hope thats another piece of the puzzle ..


Leave a comment

(required)

No trackbacks yet.