Subject: RE: Return values to First Form From Second Form
Depending on what you are trying to do, you might be better off doing this in the opposite direction. By this I mean that you could start with the Customer form and make the ORder form a response document to the customer form, sort of a parent/child relationship. This way Notes does all the work for you behind the scenes. All you would have to do is to set some properties in the info box for the 2 forms. Specifically, the customer form should be set as a “Document” (the default) and the Order form set as a “Response”. You set these in the “Type” section of the Form properties info box. Then on the Order form’s info box properties also check the “Formulas inherit values from selected document” checkbox. Additionally you would have to set formulas for the fields on the Order form so that they inherit values form their parent form. For example the CustomerCode field would be set as a computed text field with a value = “CustomerCode” without the quotes.
If the above doesn’t help your particular scenrio then the backend approach shoudl be used. This means using the backend classes in LotusScript. A typical approach would be to get a handle to both of the forms (ORder and Customer) via their applicable events, run some lotusscript and reopen the form in the front end to see your changes. Here’s a possible scenario
Form A - Order
Form B - Customer
Add a hidden field (editable) on both forms to trap the document’s id so you can use it to find the document from a view. On form A call it “OrderDocID” and on Form B call it “PrevDocID”. The code for these 2 fields should be as follows:
“OrderdocID” @Text(@DocumentUniqueId)
“PrevDocId” just leave blank
Using the same fields from my previous post but with a little difference as follows:
-
Create the desired fields on the Order form, “CustomerName”, “CustomerCode” in that order from top down or left to right, along with your other fields that would normally be on this form.
-
Add a button, “Create Customer”, which in addition to loading the Customer form will save the order form and its unique document id in the background. You no longer need the “Update button”.
Here’s the code for the “Create Customer” button:
Dim session As New NotesSession
Dim ws As New NotesUIworkspace
Dim thisui As NotesUIDocument, nextui As NotesUIdocument
Dim server As String, dbfile As String, newform As String
Dim db As NotesDatabase
Dim thisdoc As NotesDocument, nextdoc As NotesDocument
Set thisui = ws.currentdocument '(case doesn't matter in lotusscript)
Set thisdoc = thisui.Document
Call thisdoc.save (True, True)
tdocid = thisdoc.universalid
thisdoc.saveoptions="0"
Set db=session.currentDatabase
server = db.server
dbfile = db.FilePath
newform = "Customer"
Set nextui = ws.ComposeDocument( "", dbfile, newform )
Set nextui = ws.currentdocument
Set nextdoc = nextui.document
nextdoc.prevdocid = tdocid
Call nextui.gotofield("customercode")
Call thisui.close
-
Create the desired fields on the Customer Form, “CustomerCode”, “CustomerName”,all text editable plus other fields as desired
-
Add a button to the Customer form called “Pass Values Back” or anything you want. Here’s the code for that button:
Sub Click(Source As Button)
Dim session As New Notessession
Dim db As NotesDatabase
Dim ws As New NotesUIworkspace
Dim thisui As NotesUIdocument, thisdoc As Notesdocument
Dim ordercustname As String, ordercustcode As String
Set thisui = ws.CurrentDocument
ordercustcode = thisui.fieldgettext("CustomerCode")
ordercustname = thisui.fieldgettext("CustomerName")
Set thisdoc = thisui.Document
Set db=session.currentdatabase
Set prevdoc = db.getdocumentbyunid(thisdoc.prevdocid(0))
prevdoc.CustomerCode = ordercustcode
prevdoc.CustomerName = ordercustname
Set prevui = ws.EditDocument(True, prevdoc)
thisdoc.saveoptions="0"
’ Call prevui.gotofield(“CustomerCode”)
Call thisui.close
End Sub
The code works like this. Edit the Order form and click the “Create Customer” button. This saves the order form, gets its uniquedocument id,closes the order form,loads the Customer Form and transfers into its hidden “prevdocid” field, the uniquedocumentid of the order Form. This way we can always find this document in the database. Now edit the customer form and enter the desired values for Customer Code and Customer Name and other fields. Then click the “Pass Values Back” button. This will close the customer form, find the order form that it relates to, open it on the screen and transfer the desired values to the proper fields on the order form.
Make sure that you have designated a form as your “default” database form in your database. This is done in the form’s info box properties by selecting “Default database form” and it could be any form.
Now this can be modified as you desire. for instance I’ve chosen to close the front end documents to make the transfer smoother, but you don’t have to. Also I’ve not saved the entries onto the customer form, but again you could save them if you wish. This is just to give you a little head start in what you are trying to do.
Good luck,