OpenNTF.org - append selected documents from
My Links (Not logged in)
Code Bin Search
 
Hosted by Prominic.NET
Rate This Code
5 - brilliant stuff
4 - very nice
3 - average
2 - needs work
1 - bad
   OpenNTF Code Bin
About This Code
Brief Description:
append selected documents from a view in a table an mail it to current user 
Rating:
Rating: 4 , Number of votes: 1 
Contributor:
Umesh M Patil 
Category:
Lotusscript 
Type:
Email 
Notes Version:
R7.x 
Last Modified:
15 Feb 2010 
OpenNTF Disclaimer

All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.

Code / Description
the code will append selected documents from a view in a table an mail it to current user.
Usage / Example
Sub Click(Source As Button)

Dim strSubject As String
Dim strViewName As String

Dim gSession As New NotesSession
Dim UserName As New NotesName(gSession.UserName) ' - - - user name for mail to send

Dim Ws As NotesUIWorkspace
Dim UIView As notesUIVIew

Dim gDb As NotesDatabase
Dim selctedDocColl As NotesDocumentCollection
Dim gDoc As NotesDocument

Dim gView As NotesView
Dim gViewNav As NotesViewNavigator
Dim gViewEntry As NotesViewEntry

Dim memo As NotesDocument
Dim rtitem As NotesRichTextItem ' - - - for handling mail body
Dim rtt As NotesRichTextTable

Dim colorObject As NotesColorObject

' On Error Goto errorHandle

Set Ws = New NotesUIWorkspace
Set UIView = WS.CurrentView


Set gDb = gSession.CurrentDatabase
Set selctedDocColl = gDb.UnprocessedDocuments
' - - - if no one document selected , prompt a user

If selctedDocColl.Count = 0 Then
Messagebox "Select at least one document to receive the newsletter",64,gDb.Title + " Information"
Exit Sub
End If

Set gDoc = selctedDocColl.GetFirstDocument
Set gView = UIView.View' - - - Handle of view where docs belongs

Set gViewNav = gView.CreateViewNav ' - - - create view navigation

strViewName = gView.Name
If Instr(strViewName,"\") > 0 Then
Mid$(strViewName, Instr(strViewName,"\"),1) = " "
End If

Print " Sending Newsletter - Start"
' - - - newsletter Subject

strSubject = gDb.Title +" - Newsletter - " + strViewName
Set memo = New NotesDocument (gDb)
memo.Form = "Memo"
memo.SendTo = UserName.Abbreviated
memo.Subject =strSubject
Set rtitem = New NotesRichTextItem(memo, "Body")

REM Get the table

Dim rtnav As NotesRichTextNavigator
Set rtnav = rtitem .CreateNavigator

'Checking existance of any Table
If Not rtnav.FindFirstElement(RTELEM_TYPE_TABLE) Then
'Create a table
Call rtitem.AppendTable(1, gView.ColumnCount+1)
Set rtnav = rtitem.CreateNavigator ' - - - for accesing table in mail body
End If

'Creates an handle to the table.
Set rtt = rtnav.GetFirstElement(1)
rtt.Style = 2

Set colorObject = gSession.CreateColorObject
colorObject.NotesColor = COLOR_WHITE
Call rtt.SetAlternateColor(colorObject)


'First cell is skiped with a value ""
Call rtnav.FindFirstElement(RTELEM_TYPE_TABLECELL)
Call rtitem.BeginInsert(rtnav)
Call rtitem.AppendText(" ")
Call rtitem.EndInsert

' - - - table/view column headings
Forall column In gView.Columns
Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
Call rtitem.BeginInsert(rtnav)
Call rtitem.AppendText(column.Title)
Call rtitem.EndInsert

End Forall

counter=1
While Not (gDoc Is Nothing)

Set gViewEntry = gViewNav.GetEntry(gDoc) ' - - - get corresponding entry in view for accessing column values
If Not gViewEntry Is Nothing Then
Print "Processing selected document " + Cstr(counter ) + " / " + Cstr(selctedDocColl.Count)
Call rtt.AddRow(1)
Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL) ' - - - finds next table cell

Call rtitem.BeginInsert(rtnav)
Call rtitem.AppendDocLink(gDoc, gDb.Title) ' - - - append doc link in first column
Call rtitem.EndInsert
' - - - add all column values for each doc in table
Forall v In gViewEntry.ColumnValues
Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
Call rtitem.BeginInsert(rtnav)
'If v.IsHidden = False Then
Call rtitem.AppendText(v)
'End If
Call rtitem.EndInsert
End Forall
End If
Set gDoc = selctedDocColl.GetNextDocument(gDoc) ' - - - next selected document

'Break the table when counter is multiple of hundred.
If Int(counter /100) = counter /100 Then
Call rtitem.AppendTable(1, gView.ColumnCount+1)
Call rtnav.FindNextElement(1)
Set rtt = rtnav.GetElement
End If
counter = counter + 1
Wend

' - - - Send the Newsletter
Call memo.Send (False)
Print "Sending Newsletter - Complete"
Print "Requested Newsletter Sent. Check your email"
End Sub

 Comments
Posted by Jim Fricker on 01/16/2011 11:46:58 PMAlternatively you could just use....
@Command([CopySelectedAsTable]);
@Command([MailComposeMemo]);
@Command([EditGotoField]; "Body");
@Command([EditPaste]);
@Command([EditGotoField]; "EnterSendTo")
 Add your comment!