Link to home
Create AccountLog in
Avatar of jforget1
jforget1

asked on

Trouble copying field values from one form to another.

Have an order form that I use, I am trying to add code so that when a user clicks a Submit button for the order it will send out a tracer to get approval for that order, but also open a separate order form, in this case for peripherals. They have the same common user and address fields. I have also set the second peripheral form with "Formulas inherit values from selected doc" but when I click the button with the code below it does not carry any of the values over from the order form.
Note I have one hardware doc and then a separate peripherals doc. Can I copy field values from different forms? If so what can I tweak in the code. I have tried the @Command(Compose) in a couple spots but it still carries no values over to the second form.

Any help is appreciated.
FIELD status:="Pending Approval";
FIELD submit_flag:="done";
FIELD submit_date:=@Today;
SendTo := approver;
CopyTo := "";
BlindCopyTo := bcc;
Subject := "IBPC Admin Equipment Order for " + username_hidden + " requires your approval";
Remark := "An IBPC Admin Equipment Order has been entered for " + username_hidden + ". Your approval is required. Please click on the following link and approve or reject the request.";
@Prompt([Ok];"Order Received.";"Thank you for completing this order. Your order has been received and is pending approval.");
@MailSend(SendTo; CopyTo; BlindCopyTo; Subject; Remark; "";[IncludeDoclink]);

@Command([Compose];"ibpc_order_form_peripherals");

@PostedCommand([FileSave]);
@Command([FileCloseWindow]);
@PostedCommand([FileCloseWindow])

Open in new window

Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

A carry-over only happens if there is a default value formula in the second form. That formula uses field values from the open document.
Avatar of jforget1
jforget1

ASKER

So if I set all the fields on the second form as editable, but use the field name as the default value would that work?
Tried setting the defualt value on the second form to the field names, that does not bring the field values over. Is the placement of the @Command(Compose) causing me problems?
If I remember correctly, the current document is taken as source. It could be the currently selected document in a view, or a currently open document. The field's names and values are copied over to the next document, but ONLY to calculate default values (and I think also the computed fields). After that first calculation, the copied fields are discarded. So field names of the "sending" documents should be used in the "receiving" document.
Have tried everything I can think of here. Moved the command to launch the form to various spots. Checked that all the fields have the same field name with the default value set to the same value. None of the fields transfer over. Trying to think of what I could be missing here. Will keep trying.
If you can assemble a test database with the essential forms and documents, I wouldn't mind to have a look. My mail address is in my EE profile. If you send me a mail with the zipped database, you accept to have to send it to any other expert who asks for it, since the procedure is bending the EE-rules a little.
Thanks I have just sent over the files and what forms are involved.
...unzipped... :-P but thanks :-)
It was zipped when I sent it. Not sure what happened after that. Appreciate you taking a look.
What *may* be the case: the Save is too late. Why use a PostedCommand? Also, if a new document is submitted, the MailDocLink won't work, for it only works with an existing document (saved). Try to change the code, somewhat like this:

FIELD submit_date:=@Today;
SendTo :="X";
CopyTo := "";
BlindCopyTo := bcc;
Subject := "xxx";
Remark := "xxx";
@Prompt([Ok];"Order Received.";"Thank you");
@Command([FileSave]);

@MailSend(SendTo; CopyTo; BlindCopyTo; Subject; Remark; "";[IncludeDoclink]);

@PostedCommand([Compose];"your_order_form_peripherals");

@PostedCommand([FileCloseWindow])
Tried the suggestion and a few tweaks of it as well. Still not carrying over the field values to the new form.
Maybe it just isn't possible (in Formula). On the other hand, it's rather easy to do in LotusScript.

Easiest way is to prepare a NotesDocument with some fields already set, followed by an EditDocument.
sjef, attached is LS code that I use for a tracer email in another DB. Could I use this as a starting point? How would I add in the command to open the new form and then how can I transfer the values from the current record over to the new form?
Sub Click(Source As Button)
	Dim session As New NotesSession 
	Dim db As NotesDatabase
	Dim uidoc As NotesUIDocument
	Dim doc As NotesDocument
	Dim ws As New notesuiworkspace
	Dim emaildoc As NotesDocument
	Dim Item As NotesItem
	Dim rtitem As NotesRichTextItem
	Dim sNamesArrB(1)As String
	Set uidoc=ws.currentDocument
	Set doc = ws.currentDocument.Document
	Set db = session.CurrentDatabase
	On Error Resume Next
	
		Set emaildoc = db.CreateDocument
		emaildoc.form = "vap_wiped_tracer" 'Form name of Letter
		emaildoc.sendto = doc.approver
		emaildoc.CopyTo = ""
		emaildoc.current_asset = doc.current_asset
		emaildoc.user_adjusted = doc.user_adjusted
		emaildoc.alt_name = doc.alt_name
		emaildoc.Subject = "Removal Request has been completed and device wiped for " + doc.user_adjusted(0) + doc.alt_name(0) +  "!"               
		Set rtitem = New NotesRichTextItem(emaildoc, "Doclink")
		Call rtitem.AppendDocLink(doc, "") 
		Call emaildoc.Send(True)
		Set uidoc = ws.EditDocument( True )
		Call uidoc.save
		Call uidoc.Close
	End Sub

Open in new window

As far as I can see, yes indeed, you can use some of that code.

To do:
- lines 1-15: clean up
- lines 16: use newdoc instead of emaildoc
- line 17: set the form you need
- lines 18-27: copy the fields you need from olddoc to newdoc
- line 26: remove the send
- line 27: use ws.EditDocument(True, newdoc)
- lines 28-29: remove the save+close
I was thinking that I could update line 17 to the form that needs to go out to the user on submission. I then need to add something to create the new "peripherals" form and carry the field values from the form the user is on over to the new peripherals form that was just created in the button. Basically it is a matter of click the button, a tracer is sent for the hardware order, then a new Peripheral form is opened and key field values, shipping etc, is carried from the hardware form to the peripherals form.
ASKER CERTIFIED SOLUTION
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer