Ask the Expert

Adding buttons and auto-fill fields

I have created a small department database that holds, dept, name, phone, email address, etc.

I have created a view that has name, phone, and email (sorted by dept). I would like to add an "Email" button so that the user can "mark" people and then click the button and the program opens a blank memo with the "To" field filled in with all of the peopled that were marked.

I've been programming for many years, but am relatively new to Notes/Lotus Script programming, so I understand the concept of what needs to be done (read view, fill up array of some sort with people marked, open email with array field in the To field). However, I can't find the proper keywords to use to do this.

How is this accomplished? Again, with being a newbie, examples would be great.

There are two different issues here. The first is how to get the list of selected people. The second is how to compose and send the email. In this case, I am going to assume that you want to manually edit the memo before it is sent. If that were not the case, you could create one in memory and send it very easily:

    Dim session As New notessession
    Dim db As NotesDatabase
 Set db=session.CurrentDatabase
    Dim report As NotesDocument
 Set report=db.CreateDocument
 report.subject={Your agent "}+session.CurrentAgent+-
         {" in database "}+db.ti+{" has failed.}
 Call report.Send(False,"Bob the")

But to edit the memo before sending, you will need to have a form that you can use to edit it in the UI. Now, you can create a form in your database and give it appropriate fields, but in this case I'm going to show you a different way. You can actually open the user's mail file, create the memo there and let them edit and send it. It's fairly simple to do, but you do have to keep in mind one point. Often, when doing this sort of thing, you will want to add a link to a document, view, or database to the email before you edit it. I've done that below by setting a NotesRichTextItem to point to the body field of the new memo. But for this to work, the new memo document must be SAVED TO DISK before it is opened for edit. Otherwise, what the agent puts in the body field will be lost.

    Public Sub MailxSendWithEdit(ByVal sendto As Object, ByVal subject As String, ByVal remark As String)
        Dim ws As New notesuiworkspace
        Dim session As New notessession
        Dim db As NotesDatabase
        db = session.currentdatabase
        Dim memo As notesdocument

        'Create memo... 
        memo = db.createdocument
        memo.form = "Memo"
        memo.subject = subject
        memo.sendto = sendto
        Dim rtitem As New notesrichtextitem(memo, "Body")
        Call rtitem.appendtext(remark)

        On Error Resume Next

        'Optionally add some text and links before editing... 
  Call rtitem.appendtext(Chr(10)+{Something has happended…} )
        Call rtitem.appendtext(Chr(10))
  Call rtitem.appendtext(Chr(10)+_
             {Follow this link to the databasse-->})
        Call rtitem.appenddoclink(db, "Link")

        'Find the user's mail file... 
        Dim usermailfile As Variant
        Dim maildb As New notesdatabase(usermailfile(0), usermailfile(1))
        Dim memo1 As notesdocument, uidoc As notesuidocument

        'Save the memo, then copy it's contents to a new memo in the mailbox... 
        Call, False, False)
        unid = memo.universalid
        memo = session.currentdatabase.getdocumentbyunid(unid)
        memo1 = maildb.createdocument
        Call memo.copyallitems(memo1, True)
        Call memo.remove(True)

        'Then open the document for editing. . . 
        uidoc = ws.editdocument(True, memo1, False)
        If memo1.sendto(0) <> "" Then
            Call uidoc.gotofield("Body")
        End If

Now, I realize I haven't answered the core question: "How do I get the list of names?" That's easy, we use a standard code snippet to walk the view. And here it is:

       ' Get collection of all selected documents. 
 Set Selected=db.UnprocessedDocuments              
       Dim sendTo As New NotesItem(memo, "SendTo")

       ' process selected documents (In random order ). 
 For i=1 To Selected.Count                                               ' 
  Set doc=Selected.getnthdocument(i)   


 Next ' i

Here I have modified a standard "walk selected" pattern to insert the senders into the "SendTo" field of the memo we are constructing.

This was first published in September 2006

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: