Domino Server表单提交后用LotusScript获取字段值发送自动回复
Got it, let's get this sorted out for you! The key issue here is that you're not referencing the submitted contact form document in your code—right now you're hardcoding test@gmail.com instead of pulling the user's email and name from the form they just submitted. Here's how to fix it, step by step:
1. Get the Submitted Form Document
First, you need to access the document that was just submitted by the user. This depends on where your LotusScript is running:
- If this is a WebQuerySave agent (the most common scenario for web-based contact forms): Use
session.DocumentContextto get the submitted document. - If this is a form's PostSave event: Use
Source.Document(your subroutine will need aSource As NotesUIDocumentparameter).
2. Extract Field Values
Once you have the submitted document, use GetItemValue() to pull the ContactName and EmailAddress values. Note that LotusScript is case-sensitive, so make sure the field names match exactly what's on your form.
3. Updated Working Code
Here's the revised code with all these changes, plus error checking to avoid runtime issues:
Sub Initialize Dim Session As New NotesSession Dim db As NotesDatabase Dim email As NotesDocument Dim submittedDoc As NotesDocument ' Holds the user's submitted contact form Dim contactName As String Dim emailAddress As String Set db = session.CurrentDatabase ' Get the submitted document (use this for WebQuerySave agents) Set submittedDoc = session.DocumentContext ' --- Alternative: If using PostSave event, replace the line above with: ' Set submittedDoc = Source.Document ' (And update the subroutine definition to: Sub PostSave(Source As NotesUIDocument)) ' Check if we actually got a document to avoid errors If submittedDoc Is Nothing Then Print "Error: No submitted contact form found." Exit Sub End If ' Extract field values (use the EXACT field names from your form) contactName = submittedDoc.GetItemValue("ContactName")(0) emailAddress = submittedDoc.GetItemValue("EmailAddress")(0) ' Validate the email address isn't empty before sending If Trim(emailAddress) = "" Then Print "Error: No email address provided in the form." Exit Sub End If ' Build the confirmation email Set email = db.CreateDocument email.Form = "Memo" email.Principal = "noreply@test.com@test" email.From = "noreply@test.com" email.InetFrom = "noreply@test.com" email.Subject = "Email Confirmation" ' Personalize the body with the user's name email.Body = "Dear " & contactName & "," & Chr(10) & Chr(10) _ & "Thank you for reaching out! We've successfully received your submission and will respond as soon as possible." & Chr(10) & Chr(10) _ & "Best regards," & Chr(10) _ & "Your Team" ' Send the email to the user's provided address Call email.Send(False, emailAddress) End Sub
Key Notes to Remember
- Case Sensitivity: The field names (
ContactName,EmailAddress) must match exactly what's defined on your Domino form—LotusScript will not recognize lowercase or misspelled names. - GetItemValue Returns an Array: Since most form fields are single-value, we use
(0)to grab the first element of the array returned byGetItemValue(). - Permissions: Ensure your agent has the necessary rights to send mail from the Domino server, and that the server's mail routing is configured correctly.
- Web Form Validation: If this is a web form, double-check that your HTML input fields have a
nameattribute matching the Notes field name (e.g.,<input type="text" name="ContactName">).
内容的提问来源于stack exchange,提问作者SimonB

