Update field on different form?

I have 2 forms. Form “A” has a button that incremiments a numeric computed field and then opens form “B”.

Sometimes this button is used by mistake and the user wants to under the operation. So, I have a cancel button on form “B” that closes form “B”.

What is the best way to enable the cancel button on form “B” to de-incremint the numeric field on form “A” back to its original value before closing?

Subject: RE: Update field on different form?

If the field on A is displaying the number of related “form B” documents that exist, then I think you would be better off with a “Computed for display” field on A, using @Elements(@DbLookup(…)). Updating a field on a different document that may or may not be open on the user’s screen (nothing prevents them from closing A while B is still open) entails many difficulties.

This question comes up frequently and if you search here you will find other approaches described, such as using a modal dialog box to edit B. I think it’s better to keep things simple.

Subject: Update field on different form?

Your problem seems to be that when you create Form B the Form A is still open, so if you cancel B and at the sametime update the number in A you run the risk of getting a save conflict.

I suggest that the button to create Form B is a script action to increment the value, create B (passing it the unique doc id of A) then close A and present the user with the new B document.

If the new B document is cancelled then the cancel action closes the new Form B window and also locates form A and and reduces the number by one.

So on Form A button something like:

Dim ws As New NotesUIWorkspace

Dim doca As NotesDocument, docb As NotesDocument

Dim Session As New Notessession

Dim uidoc As NotesUIDOcument



Set db = session.currentdatabase

Set doc = ws.currentdocument.document

Set uidoc = ws.currentdocument

' Increment your number field on Form A

doc.NumberFld = doc.NumberFld(0) + 1

Call doc.save(True, True)

Call uidoc.save

’ Create B form copying across the Form A unique ID

Set docb = db.CreateDocument

docb.form = "FormB"

docb.parentref = doc.UniversalId

docref = docB.Universalid          

Call docb.save(True, True)



Set reopendoc =db.GetDocumentByUNID( docref )

Call uidoc.close   ' Close Form A

Call ws.EditDocument(True, reopendoc) ' open form B

and on Form B cancel action

Dim ws As New NotesUIWorkspace

Dim doca As NotesDocument, docb As NotesDocument

Dim Session As New Notessession

Dim uidoc As NotesUIDOcument



Set db = session.currentdatabase

Set docb = ws.currentdocument.document

Set uidoc = ws.currentdocument

' get Form A

Set doca =db.GetDocumentByUNID( docb.parentRef(0) )

’ take one off the number field and save it

doca.NumberFld = doca.NumberFld(0) - 1

Call doca.save(True, True)

’ open Form A

Call ws.EditDocument(True, doca)	

’ make Form B non edit mode

uidoc.Editmode =False

’ call a delete on Form B

Call uidoc.DeleteDocument

(NB: NumberFld is a numeric field on the Form A, ParentRef is a text field on Form B)

(NB2: Form B will still be seen in the views until the view is refreshed by the user