Hello all,
I have an agent that runs in the save event in of a formA which calculates the total value of different fields and collects these totals into a grand total that should be replaced and saved in another fromB .
when I debug the agent I see that all the figures are correct and the grand total is correct still it is never saved in formB unless I close and reopen the formB
here is my code
Sub Initialize
Dim session As NotesSession
Set session = New NotesSession
Set db = session.currentdatabase
Set SettDoc = db.GetProfileDocument(“Settings”)
Dim Headview As NotesView
Dim headdoc As NotesDocument
Dim DetailDoc As notesdocument
Dim DetailView As notesview
Dim DetailDC As notesdocumentcollection
Set headdoc=session.DocumentContext
Set Headview=db.getview(“Purchase Order Details by ParentID”)
Set DetailView=db.getview(“PID”)
Set DetailDC= DetailView.GetAllDocumentsByKey(headdoc.id(0) ,True )
Set DetailDoc = DetailDC.GetFirstDocument
Dim HeaderDoc As notesdocument
Dim HeaderView As notesview
Set HeaderView=db.getview(“POHdrIDAll”)
Set HeaderDoc=HeaderView.getdocumentbykey(DetailDoc.id(0))
Dim OrderTotal As Double
Dim itemcounter As Integer
itemcounter=0
OrderTotal=0
If detaildc.Count=1 Then
OrderTotal=Cdbl(DetailDoc.Qty(0))*Cdbl(DetailDoc.UnitPrice(0))
OrderTotal=OrderTotal
Else
itemcounter=itemcounter+1
While Not(DetailDoc Is Nothing)
OrderTotal=OrderTotal+DetailDoc.Total(0)
Set DetailDoc = DetailDC.GetnextDocument(DetailDoc)
Wend
End If
If Not(HeaderDoc Is Nothing) Then
Dim HTotal As NotesItem
HeaderDoc.OrderTotal=OrderTotal
Call HeaderDoc.save(True,False)
End If
End Sub
any help will be appreciated
thanks