: 4582 | 108668 | 12353

Emailing a subform from the current UI document 
Use this IdeaSpace to post ideas about the Notes Client.

: -7
: 1
: 8
: Notes Client / Other Database Applications
: Email, Subform, Copy, clipboard
: Chad Martin75 11 Aug 2008
:
: / Email


I'm sure most of you are familar with the simple @Command([MailForward]) function. @Command([MailForward]) forwards the current document by placing its entire contents into a mail memo which the user then addresses and sends. I was tasked with duplicating this functionality, but for a subform on the current document. Futhermore, the customer wanted to the memo to be executed through the backend and sent via the click of a button.

Approach:
The key to this accomplishing this task is to isolate the subform in its own form. After the subform is isolated, its entire contents can be copied to the clipboard, pasted it into a rich text field, and sent to a specified user. Follow these 3 steps to create the basic forms and code for this utility - or - to download a sample copy of my database go to:
http://www.openntf.org/Projects/pmt.nsf/HomeLookup/97CEA8C9251DA3BE862574A2006FA7B8?OpenDocument

Step 1:
a.) Create a hotspot button on the subform you wish to email and add this code to the 'click' event:
(note: In the 'hide-when' options of the hotspot button, check the box for hiding when "Copied to the Clipboard")

'This button will switch the form name of the current document and open the document using the temp form.
Dim strOrgForm As String
Dim ws As New NotesUIWorkspace
Set doc = ws.CurrentDocument.Document
Let strOrgForm = doc.Form(0) 'capture the original form name
doc.ReplaceItemValue "Form", "TempForm" 'switch the form to the temp 'email' form.
Call ws.EditDocument(False,doc) 'reopen the document with the 'temp' form.
doc.ReplaceItemValue "Form", strOrgForm 'replace the form name back to its original name.

-----------------------------------------------------------------------------------------
Step 2:
a.) Create a form in your database and name it "TempForm".
b.) Insert the subform from Step 1 into "TempForm"
c.) (optional: If your underlying original form as richtext fields with attachments, add those richtext fields on the tempform in a hidden section. The section must be hidden and the section properties must be set to 'auto-collapse' on open. Otherwise the attachments from the main form will appear at the bottom of the email when it is sent. This step is not necessary if your underlying form does not have rich text fields.)
d.) copy and paste the following code into the "PostOpen" event the "TempForm" subform.

Dim db As NotesDatabase
Dim ns As New NotesSession
Dim uidoc As NotesUIDocument
Dim docMemo As NotesDocument
Dim ws As New NotesUIWorkspace
Dim ndt As New NotesDateTime("12/31/1899")

'The postopen event will copy the entire unhidden contents of the form to the user's clipboard
'Then it will grab the memo document saved in the database and open it.

Set db = ns.CurrentDatabase
Set uidoc = ws.CurrentDocument
Call uidoc.SelectAll
Call uidoc.Copy
Call uidoc.Close

Set dcMemo = db.Search(|Form = "Memo"|,ndt,1) 'Get the Memo document in database. There should only be 1 memo document
If dcMemo.Count = 0 Then 'If the memo document is not created, than create a new one
'This code will only execute the first time someone uses this utility.
Set docMemo = New NotesDocument(db)
docMemo.ReplaceItemValue "Form", "Memo"
Else
Set docMemo = dcMemo.GetFirstDocument 'otherwise just get the existing memo document
End If

'In this example we are sending the subform to the current user.
docMemo.ReplaceItemValue "SendTo", ns.CommonUsername
'If you wish to make the sendto field variable, add a hidden field to the tempform Form, popluate it, and then reference it here like this:
'docMemo.ReplaceItemValue "SendTo", uidoc.Document.GetFirstItem(your fieldname goes here).Values
docMemo.ReplaceItemValue "CopyTo", "" 'Add more people to CC if desired
docMemo.ReplaceItemValue "Subject", "Test: Emailing a subform" 'add a subject to your memo
docMemo.ReplaceItemValue "Body", "" 'clear the body field each time before opening the memo
Call ws.EditDocument(True,docMemo) 'Open the Memo document.

------------------------------------------------------------------------------------------------
Step 3:
a.) Create a form in your database and name it "Memo"
b.) Create an editable rich text field on the Memo Form and name it "Body".
c.) copy and paste the following code into the "PostOpen" event the "TempForm" subform.

Dim uidoc As NotesUIDocument
Dim ws As New NotesUIWorkspace

'The postopen event of this form will paste the contents of the user's clipboard into the body field
Set uidoc = ws.CurrentDocument
Call uidoc.Paste 'paste the subform into the body field of the uidoc (body field is default focus)
Call uidoc.Save 'the uidoc must be saved to capture the rich text
Call uidoc.Document.Send(False,False) 'send the memo document
Call uidoc.Close




1) Rob Goudvis6585 (12 Aug 2008)
I don't see how an enduser might know about "subforms".
2) Chad Martin75 (12 Aug 2008)
It doesn't have to be a subform. It can be any portion of the current UI document which the user wants to email.
3) Anjaneya Prasad Banda11 (14 Aug 2008)
Good Solution

I got same requirement This is very helpfull when the form contains tabbed tables or subforms or any big content form and we need to send part of it.

Prasad
4) Morten Clausen421 (15 Aug 2008)
RenderToRTItem is your friend with a little fiddling of the Form-field, I think. I seem to recall doing something like this with a (possibly computed) subform on a very simple form: changing the Form of the document-to-be-sent, rendering the changed document to an RT-item on another document and mailing that. Long time ago so details are a little fuzzy... :-)










:
:




Welcome to IdeaJam


You can run IdeaJam™ in your company. It's easy to install, setup and customize. Your employees, partners and customers will immediately see results.

Use IdeaJam to:

  • Collect ideas from employees
  • Solicit feedback and suggestions from employees and customers
  • Run innovation contests and competitions
  • Validate concepts
  • Use the power of "crowd-sourcing" to rank ideas and allow the best ideas to rise to the top

IdeaJam™ works with:

  • IBM Connections
  • IBM Lotus Quickr
  • Blogs and Wikis
  • Websphere Portal
  • Microsoft Sharepoint
  • and other applications.

IdeaJam has an extensive set of widgets and API's that allow you to extend and integrate IdeaJam™ with other applications.

Learn more about IdeaJam >>






IdeaJam developed by

Elguji Software Logo