Cache problem with global variable

Hi all,

i have a strange behavior with a agent that calls a function in a script library.

Here is the scenario (hoping that some of you can reproduce this …)

I have 2 empty forms (Form ‘A’ anf form ‘B’)

I have 2 views (view ‘A’ for Form ‘A’ and view ‘B’ for form ‘B’)

 View 'A' has the 1st column sorted with value 'O' (hard coded)

I have 1 document created with form ‘A’

I have 1 simple action agent that changes the field ‘FORM’ to ‘A’

I have 1 script agent as goes :

Use “FunctionsLib”

Sub Initialize

dim s as new notessession

Dim db As NotesDatabase

Dim zzdoc As NotesDocument

Dim MyView As notesview

Dim collectionExpDB2 As NotesDocumentCollection

Dim NotesDateTimeStart As New NotesDateTime(Now)

Set db = s.CurrentDatabase

DO

Set MyView = db.getview(“A”)

Call MyView.Refresh

Set collectionExpDB2 = MyView.getalldocumentsbykey(“O”)

Set zzdoc = collectionExpDB2.getfirstdocument

While Not zzdoc Is Nothing

If zzdoc.form(0) = "B" Then    ' this should always be false !!

   delete zzdoc

end if

If zzdoc.Form(0) = “A” Then

    zzdoc.form = "B"

    zzdoc.Save True, False

    ExportData  zzdoc           ' This is in a script library

end if

Set zzdoc = collectionExpDB2.getNextdocument (zzdoc)

Wend

Sleep 30 ’ sleeps for 30 seconds

Dim diff

Dim NotesDateTimeNow As New NotesDateTime(Now)

diff = NotesDateTimenow.TimeDifference(NotesDateTimestart)

If diff > 600 Then 'the agent runs non-stop for 10 minutes

  Exit Sub

End If

Loop

end sub

And i have 1 script library (‘FunctionsLib’) as goes

(Declarations)

Dim doc As NotesDocument

Sub ExportData (MyDoc As NotesDocument)

’ if declared locally, i don’t have the problem.

’ Dim doc As NotesDocument

Print "Start of  function"

Set doc = MyDoc

Print "End of function"

End Sub

So, my problem is when the agents gets the collection from view ‘A’, it sees 1 document with the good value (‘A’) in the form field. The agents then changes this value to ‘B’. so the document dissapears from the view ‘A’ and goes in the view ‘B’. If you use the agent to toggle the document back to view ‘A’, it reappears in the view ‘A’ and the agent that is still running gets the doc with the collection. The problem is that my field value (in the agent) has ‘B’ as value ??? You have to toggle back the document within the same agent cycle (300 seconds)

If you have the same problem, try changing the :

dim doc as notesdocument place from (Declarations) to locally to the function and the problem dissappears !

I don’t know if this is clear but it is a simple test for you guys to try out and let me know if this is a big bug or not !!