0
votes

I have been asked to set up an e-mail action button on a form on a lotus notes database set up by a predecessor. The problem is the form pulls in data from an embedded view so when I e-mail the document, the data from the embedded view is missing. Is there any way to save the data from the embedded view in the document which can then be e-mailed. The Lotus Notes version is 9.

3

3 Answers

1
votes

As Rich says, you can't mail a document and include data stored in other document that are viewed through an embedded view.

What you can do is to actually read the data and store it in the document you are mailing. I am describing one way to do it in my blog entry here: http://blog.texasswede.com/dynamic-tables-in-classic-notes/

What you do is to create a small form, representing what one row of data would look like. Put the fields on there, add formatting, etc. I am calling that form a "row template":

enter image description here

On the main form ("target form") you add a new rich text field where you later will display the embedded data. I usually set that field to be as small as possible, formatting it using Arial 1pt. In my example below, I have a few hidden (red) fields and a table (same width as the table in the template row form) for the header row. In your case you probably have many more fields, but that does not matter here.

enter image description here

You then add code in the main form (used by the document) that identify all the documents to include (the ones currently displayed by the embedded view) and loop through those documents. For each document you get the values to display, put them into a new in-memory document using the row template form, render that form into a rich text field on the target document and discard the in-memory document. Repeat until you processed all documents.

I often put the code in the QueryOpen event, so it is executed before the document is opened. The main reason for that is that I don't like embedded views, they are not attractive to users and they are much less flexible than my technique. Here is the code I use:

Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, _
    Continue As Variant)
    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim view As NotesView
    Dim col As NotesViewEntryCollection
    Dim entry As NotesViewEntry
    Dim entrydoc As NotesDocument
    Dim thisdoc As NotesDocument
    Dim datafield As NotesRichTextItem
    Dim templatedata As NotesRichTextItem
    Dim entrydata As NotesRichTextItem
    Dim doclink As NotesRichTextItem
    Dim template As NotesDocument
    Dim parentunid As String

    If source.IsNewDoc Then
        Exit Sub  ' Exit if new document, we do not have a ParentUNID or entries yet
    End If
    Set thisdoc = source.Document
    Set datafield = New NotesRichTextItem(thisdoc,"Data")
    parentunid = thisdoc.GetItemValue("ParentUNID")(0)
    Set db = session.CurrentDatabase
    Set view = db.GetView("(LookupEntry)")
    Set col = view.GetAllEntriesByKey(parentunid,True)
    Call thisdoc.ReplaceItemvalue("EntryCount",Cstr(col.Count))
    Set entry = col.GetFirstEntry
    If Not entry Is Nothing Then
       Call thisdoc.ReplaceItemvalue("LastEntryBy", _
       entry.Document.GetItemValue("Creator")(0))
       Call thisdoc.ReplaceItemvalue("LastEntryDate", _
       Format$(Cdat(entry.Document.GetItemValue("ItemDate")(0)),"mm/dd/yyyy"))
       Call thisdoc.Save(True,True)
   Else
       Call thisdoc.ReplaceItemvalue("LastEntryBy","")
       Call thisdoc.ReplaceItemvalue("LastEntryDate","")
       Call thisdoc.Save(True,True)
   End If 
   Do While Not entry Is Nothing
       Set entrydoc = entry.Document
       Set template = New NotesDocument(db)
       Call template.ReplaceItemValue("Form","RowTemplate")
       Call template.ReplaceItemValue("ItemDate", _
       Format$(Cdat(entrydoc.GetItemValue("ItemDate")(0)),"mm/dd/yyyy"))
       Call template.ReplaceItemValue("Creator", _
       entrydoc.GetItemValue("Creator")(0))
       Call template.ReplaceItemValue("Issue", _
       entrydoc.GetItemValue("Issue")(0))
       ' *** Copy Rich text Field "Issue"
       Set entrydata = entrydoc.GetFirstItem("Issue")
       Set templatedata = New NotesRichTextItem(template,"Issue")
       Call templatedata.AppendRTItem(entrydata)
       ' *** Copy Rich text Field "Action"
       Set entrydata = entrydoc.GetFirstItem("Action")
       Set templatedata = New NotesRichTextItem(template,"Action")
       Call templatedata.AppendRTItem(entrydata)
       ' *** Add doclink to entry
       Set doclink = New NotesRichTextItem(template,"DocLink")
       Call doclink.AppendDocLink(entrydoc,"Open Entry")
       Call template.ComputeWithForm(True,False)
       ' *** Refresh form
       Call template.RenderToRTItem(datafield)
       Set entry = col.GetNextEntry(entry)
   Loop
   Call thisdoc.ComputeWithForm(True,False)
End Sub

This is what it would look like in the target document:

enter image description here

0
votes

When you say the form pulls in data from an embedded view, is it one particular document contained in that embedded view? Or several?

Either way, it sounds like you need to get a handle to the document(s) through Lotusscript - don't forget, the embedded view is essentially just a view.

I would try getting a handle to the document in a way similar to this (if you are able to provide more information I could be more specific) :

dim s as New NotesSession
dim ws as New NotesUIWorkspace
dim uidoc as NotesUIDocument
dim db as NotesDatabase
dim view as NotesView
dim doc as NotesDocument
dim SearchString as String

set uidoc = ws.CurrentDocument
set db = s.CurrentDatabase
set view = db.GetView("<embedded view name>")
SearchString = uidoc.FieldGetText("<enter name of category field on form>")
set doc = view.GetDocumentByKey(SearchString, true)

if not doc is Nothing then
    ' set values from doc here, ie...
    thisVal = doc.value1(0)
    thatVal = doc.value2(0) ' etc
    ' then you can form your email
    Dim MailDoc as New NotesDocument(db)
    MailDoc.Form = "Memo"
    MailDoc.Subject = thisVal
    MailDoc.Body = thatVal
    MailDoc.SendTo = "[email protected]"
    call MailDoc.Send(false)
else
    msgbox "Can't find document"
end if
0
votes

As I understand it, you're trying to email the document, with it's form - using the Store Form In Document, feature. The idea being that someone who receives the email gets a what-the-sender-saw-is-what-I-get view of the document. Is that correct?

I don't believe that can work the way you want with an embedded view, because the embedded view element is limited to referencing a view in the same database - and the email recipient is viewing the document in his mail database where the view doesn't exist. There are ways to build Notes applications that can effectively get around the same-database restriction (see here), but you can't email all the application code. You can only email the document and stored form.