This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal


Aug 25, 2014, 4:18 AM
51 Posts

UnprocessedDocuments (Email Addresses)

  • Category: Application Development
  • Platform: All Platforms
  • Release: 9.0.1
  • Role: Developer
  • Tags:
  • Replies: 4

I am attempting to create an in-view action button that grabs the email addresses from all selected documents. The action would then create a new memo and insert the addresses into the BCC field. Does anyone have any samples or advice? Thanks in advance.

Update:

Honestly, the looping and adding to memo is stumping me a bit. I don't program that much these days. I'm including code below (I know something's missing). I want to limit the # of emails to 100, hence the who,x part. Any guidance appreciated. I want to use "who" as the value for blindcopyto. The user should be able to interact with the form vs. back-end mail send.

 
***I'm getting you must provide an item name from the start.
 
***The doc has 3 possible email addresses (in many cases #2 and #3 are blank).
 
Sub Click(Source As Button)
 
Dim session As New NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim adoc As NotesDocument
Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments
Set adoc = collection.GetFirstDocument()
 
Dim who, x
 
Do Until adoc Is Nothing
 
who = ""
For x = 1 To 100
who = who & adoc.GetItemValue("Email1")(0) & ";" & adoc.GetItemValue("Email2")(0) & ";" _
& adoc.GetItemValue("Email3")(0) & ";"
 
Print "Adding 100 email addresses (please wait)"
 
Set adoc = view.GetNextDocument(adoc)
If adoc Is Nothing Then Exit For
Next
who = Fulltrim(Split(who, ";"))
 
If Not (adoc Is Nothing) Then
Set adoc = view.GetNextDocument(adoc)
End If
Loop 
 
Dim mdoc As NotesDocument
Set mdoc = New NotesDocument( db )
mdoc.Form = "Memo"
mdoc.blindcopyto = who
mdoc.Subject = "Test"
mdoc.Body = "Test"
   ' insert mail send here (removed for testing).
 
End Sub
Aug 25, 2014, 7:00 PM
29 Posts
One way
You can try something like this.

Option Public
Sub Initialize
        Print "Start GetAddresses"
        Dim s As New NotesSession
        Dim db As NotesDatabase
        Dim collection As NotesDocumentCollection
        Dim doc As NotesDocument
        Set db = s.CurrentDatabase
        Set docCol = db.UnprocessedDocuments
        Set doc = docCol.GetFirstDocument()
        Dim emailaddresses As String
        emailaddresses = ""
        Dim first As Boolean
        first = True
       
        While Not doc Is Nothing
                Dim email1 As String
                Dim email2 As String
                Dim email3 As String
               
                email1 = doc.GetItemValue("Email1")(0)
                email2 = doc.GetItemValue("Email2")(0)
                email3 = doc.GetItemValue("Email3")(0)
               
                If first Then
                        If email1 <> "" and email2 <> "" and email3 <> "" Then
                                emailaddresses = email1 & "," & email2 & "," & email3
                                first = false
                        ElseIf email1 <> "" And email2 <> "" And email3 = "" Then
                                emailaddresses = email1 & "," & email2
                                first = False
                        ElseIf email1 <> "" And email2 = "" And email3 <> "" Then
                                emailaddresses = email1 & "," & email3
                                first = False
                        ElseIf email1 = "" And email2 <> "" And email3 <> "" Then
                                emailaddresses = email2 & "," & email3
                                first = False        
                        ElseIf email1 <> "" And email2 = "" And email3 = "" Then
                                emailaddresses = email1
                                first = False
                        ElseIf email1 = "" And email2 <> "" And email3 = "" Then
                                emailaddresses = email2
                                first = False                                
                        Else
                                emailaddresses = email3
                                first = False
                        End If
                Else
                        If email1 <> "" And email2 <> "" And email3 <> "" Then
                                emailaddresses = emailaddresses & "," & email1 & "," & email2 & "," & email3
                               
                        ElseIf email1 <> "" And email2 <> "" And email3 = "" Then
                                emailaddresses = emailaddresses & "," & email1 & "," & email2
                               
                        ElseIf email1 <> "" And email2 = "" And email3 <> "" Then
                                emailaddresses = emailaddresses & "," & email1 & "," & email3
                               
                        ElseIf email1 = "" And email2 <> "" And email3 <> "" Then
                                emailaddresses = emailaddresses & "," & email2 & "," & email3
                               
                        ElseIf email1 <> "" And email2 = "" And email3 = "" Then
                                emailaddresses = emailaddresses & "," & email1
                               
                        ElseIf email1 = "" And email2 <> "" And email3 = "" Then
                                emailaddresses = emailaddresses & "," & email2
                        Else
                                emailaddresses = emailaddresses & "," & email3
                        End If
                End If
                Set doc = docCol.getnextdocument(doc)                
        Wend
       
        Print "Original email addresses " & emailaddresses
        Dim addressArray As variant
        Dim uniqueAddressArray As Variant
        Dim uniqueAddressArrayUnder100 As Variant
       
        addressArray = Split(emailAddresses, ",")
        'remove dups
        uniqueAddressArray = ArrayUnique(addressArray)
        'limit to first 100
        If UBound(uniqueAddressArray) > 100 Then
                uniqueAddressArrayUnder100 = subset(uniqueAddressArray, 100)
                emailaddresses = Implode(uniqueAddressArrayUnder100, ",")
        Else
                emailaddresses = Implode(uniqueAddressArray, ",")
        End If
       
        Print "Unique and first 100 email addresses " & emailaddresses
       
        Print emailaddresses
       
Dim maildb As New NotesDatabase("","")
        Dim maildoc As NotesDocument
        Dim uiws As New NotesUIWorkspace
        Dim uidoc As NotesUIDocument
       
        Call maildb.Openmail()
        Set maildoc = maildb.Createdocument()
        Call maildoc.Replaceitemvalue("Form", "Memo")
        Call maildoc.Replaceitemvalue("BlindCopyTo", emailaddresses)
        Call uiws.Editdocument(true, maildoc)
       
        Print "End GetAddresses"
End Sub

Function Subset(array As Variant, n As Integer) As Variant
   Dim retVal As Variant
   Dim i As Integer
   If Not IsArray(array) Then
      Subset = array
      Exit Function
   End If
   If n = 0 Then
      Subset = ""
      Exit Function
   End If
   If Abs(n) >= (UBound(array) - LBound(array) + 1) Then
      Subset = array
      Exit Function
   End If
   If n > 0 Then
      ReDim retVal(LBound(array) To (LBound(array) + n - 1)) As Variant
   Else
      ReDim retVal((UBound(array) - Abs(n) + 1) To UBound(array)) As Variant
   End If
   For i = LBound(retVal) To UBound(retVal)
      retVal(i) = array(i)
   Next
   Subset = retVal
End Function
Aug 25, 2014, 11:12 PM
51 Posts
Thanks Oscar (UnprocessedDocuments (Email Addresses))

Oscar,

Thanks, really appreciate it. I look forward to running this evening. I'll respond asap. Can this be used in a click event? I noticed the "Sub Initialize" and wanted to make sure. Also, the custom memo form is actually in the newsletter database (same database with views where docs are selected).

Best regards,
Michael

Aug 26, 2014, 4:53 PM
29 Posts
You're welcome
Yes, it should work the same in your view action.

Okay, you can update the code to create the document in the current database instead of the mail file.
Aug 28, 2014, 1:17 AM
51 Posts
Thanks Oscar

Oscar,

Your code really helped me, thanks. I did change to create memo from local DB. Have a great week.

Best regards,
Michael


This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal