Question : Generate email and append fields to body

Hi Experts,

I am generating an email from a button on a form. It notifies the recipients to look at the document and I want it to previews two fields in the email body.

I have it working in formula language in production but it's slow and I want to convert to lotusscript.  I have everything working fine except am getting an error, "Type mismatch" on lines 38 and 40.

I need both of the fields GlobalComment(text) and Comments (rich text) to go in the body of the email along with the doclink. I'm a novice with lotusscript and have tried a few things but at this point I'm confused on what the syntax should be when appending fields and not just the text in quotes.  Does AppendText only work with text in quotes? How do you append fields?  Help please!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
Sub Click(Source As Button)
	Dim ws As New notesuiworkspace
	Dim uidoc As notesuidocument
	Dim session As New notessession
	Dim db As notesdatabase
	Dim view As notesview
	Dim doc As notesdocument, curdoc As notesdocument
	Dim dc As notesdocumentcollection
	Dim maildoc As notesdocument
	Dim Body As NotesRichTextItem
	
	Set uidoc=ws.CurrentDocument
	Set curdoc=ws.CurrentDocument.Document 
	Call curdoc.Save (False,True)
	Set db=session.currentdatabase
	Set maildoc = New NotesDocument( db )
	
	tmpname=curdoc.SendRptToTesting
	tmpname2=curdoc.CopyToTesting
	
	message=curdoc.GlobalComment 'text field
	message1=curdoc.Comments 'rich text field
	message2="Click this docklink to open complete report=========>>"
	
	maildoc.Form = "Memo"
	maildoc.Subject = curdoc.Title
	maildoc.SendTo = tmpname
	maildoc.CopyTo = tmpname2
	
	curdoc.Sent_H = "Yes"
	curdoc.Sent = "Yes"
	curdoc.Report_Date = Today
	curdoc.ReportTime = Now()
	curdoc.Draft = "No"
	
	Set Body=New NotesRichTextItem(maildoc,"Body")
	
	Call Body.AppendText(message)
	Call Body.AddNewLine(2)
	Call Body.AppendText(message1)
	Call Body.AddNewline(2)
	Call Body.AppendText(message2)
	Call Body.AppendDocLink(curdoc,"Please Click this Link to open the Document")
	Call maildoc.Send(True)
	Call curdoc.Save(True,False)
	Call uidoc.Close
	
End Sub

Answer : Generate email and append fields to body

RE: "The Comments field"

If you want to preserve the formatting and attachments, then yes, AppendText will only append plain text.  Change that line to this instead...

      Call Body.AppendRTItem(Comments)

RE: "Notes crashes and closes at the end"

Well, that's a bit harder.  I don't see anything in PostSave that would cause a crash.

Is there any code in QuerySave or the other form events?  Since were opening and closing the uidoc, all sorts of timing issues can crop up.  You'll have to be really careful in your form events, but I've used this technique many times. It's not impossible.

One thing that I do notice in PostSave is that you are getting a new handle to the uidoc even though the event method already provides one.  I've found that Notes is more stable when you use the handles that they give you.

Also, in the code that I sent you, we're setting the 'Sent' field in the back-end after the form closes, so it would not be available on the form in PostSave.  In looking at your code, I don't see a need to mess with the front-end classes at all.  I would probably change PostSave to something like this...

      Sub Postsave(Source As Notesuidocument)
            Dim doc as NotesDocument
            Set doc = Source.Document.ParentDatabase.GetDocumentByUNID(Source.Document.UniversalID)
            If (doc.GetItemValue("Sent")(0) = "Yes") Then
            ...

RE: "I need to save today's date as date only"

      Dim dt As New NotesDateTime(Now)
      curdoc.Report_Date = dt.dateOnly

RE: "I'd like to fix it here instead of the view column"

Always a good choice.  Views are slow enough already.
Random Solutions  
 
programming4us programming4us