Update a field in a form from another form

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

Subject: RE: update a field in a form from another form

Right – the document that is open on-screen is not updated when you save changes to the back-end document. You would have to do something to make the B document notice the change and update itself. This is a different operation if the document is in read vs. edit mode (if there are unsaved changes).

People sometimes work this by composing new documents using DialogBox called by an action on B, so that B retains control and can’t be closed or get other edits while A is being composed.

Alternatively, B could compose A from an action and store a pointer to the NotesUIDocument for A in a global. By periodically (using NotesTimer) checking the note ID and modified date of the new note, B should be able to tell when A was modified and update itself. Note that A should not update B, because A doesn’t know whether B is open or, if open, whether it’s in read mode.

This raises some problems if you open an existing A from a view and then open B, and edit A. B doesn’t know that A is open, so it doesn’t know to update when A is saved. So there are some limitations there.

I haven’t tried this approach, but I don’t see any reason it shouldn’t work.

Another approach is to not store the total in B, but have it computed for display.

Yet another possibility is to merge the documents and have just document B, with a table of A entries on it.

Subject: RE: update a field in a form from another form

Andre,

Thank you for the detailed and usual great response but actualy the case is A is multiple documents that are stored in an embedded view in B (B is almost a parent document to A)

in this case I should have the total computed for display in B

what do you think?

Thanks

Dalia

Subject: RE: update a field in a form from another form

I think you have to figure out a way for document A to tell document B that document B has to refresh its UI. I suggested a way to do this with a NotesTimer. Obviously you may have multiple A documents open, or the user may (try to) close the B document while some A documents are still open, and you need to deal with that somehow (by keeping track of multiple UIdocs, by using Queryclose to refuse to close B, etc).

Subject: update a field in a form from another form

Your code looks ok.

Couple of things to check:

  • Is HeaderDoc actually found in the ‘POHdrIDAll’ view using the key of the value of the ‘DetailDoc.id’ field?

  • You could try putting ‘Call HeaderDoc.ComputeWithForm(False, False)’ just before the ‘Call HeaderDoc.Save…’ line.

Alex

Subject: RE: update a field in a form from another form

Thanks Alex,

I have tried but it did not work

Thanks