Reputation: 41
I have a Contact Form that is filled out on a Domino
Server. Once the form is submitted, I want to send an automated reply to the user, confirming receipt.
I want to create the reply using LotusScript
, pulling certain data from the submitted form, such as email address, contact name.
Can someone advise how I get the value of the ContactName
/ EmailAddress
(instead of [email protected]) fields for the submitted document and use them to build the reply email? I have got this far with my limited knowledge of LotusScript
:
Sub Initialize
Dim Session As New NotesSession
Dim db As NotesDatabase
Dim email As NotesDocument
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set email = db.CreateDocument
email.form="Memo"
email.principal="[email protected]@test"
email.from="[email protected]"
email.inetfrom="[email protected]"
email.subject="Email Confirmation"
email.body="Dear ..."
Call email.Send(False,"[email protected]")
End Sub
Upvotes: 0
Views: 299
Reputation: 12060
If your code goes into an agent, and the agent, then you can get the current document from UnprocessedDocuments- Property:
Dim dc as NotesDocumentCollection
Set db = session.CurrentDatabase
Set dc = db.UnprocessedDocuments
Set doc = dc.GetFirstDocument
If the code is called from any form- event, then usually you have a Source as NotesUIDocument, if not you can get it from open document:
Dim ws as New NotesUIWorkspace
Dim uidoc as NotesUIDocument
Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
'- alternative, if from event in open document,
'- where Source is always a Parameter of type NotesUIDocument
Set doc = Source.Document
After that you can get values from the document by their item names:
strMailAddress = doc.GetitemValue( "EmailAddress" )(0)
strContactName = doc.GetitemValue( "ContactName" )(0)
email.SendTo = strMailAddress
email.Body = "Dear " & strContactName & ", asfdsdfds"
The UnprocessedDocument- Collection is defined by the agent properties. If it is „all new documents, then it will contain all documents that are new since last run.
You cycle through the collection by wrapping your code in a while loop:
Set doc = dc.Getfirstdocument
while not doc is nothing
'Your old code goes here
Set doc = dc.GetNextDocument(doc)
Wend
Upvotes: 2