Saturday, 13 September 2014

Sending email using LotusScript.

Sample code used for sending email using LotusScript.

code started from below :
Sub Initialize

 Dim session As new notessession
Dim db As notesdatabase
Dim docMail As notesdocument
Dim rtitem As Variant
Dim doc As notesdocument
Dim strSendTo As Variant
Dim strSubject As String
Dim strCopyTo As Variant

Set db=session.currentDatabase
Set docColl= db.Unprocessedocument
Set doc= docColl.getFirstDocumnet

While not doc is nothing
strSendTo= doc.getitemValue(sendTo)
 strCopyTo= doc.getitemValue(CopyTo)
Set docMail=db.createdocument
Set rtitem=docMail.CreateRichTextItem(“Body”)

If strSendTo(0) = "" Then Exit Sub

'=====set mail
docMail.Form = “Memo”
docMail.From = session.UserName
docMail.Principle = session.UserName
docMail.SendTo = strSendTo

If Isarray(strCopyTo) Then
If strCopyTo(0)<>"" Then
docMail.CopyTo = strCopyTo
End If
Else
If strCopyTo<>"" Then
docMail.CopyTo = strCopyTo
End If
End If

docMail.Recipients = strSendTo
docMail.Subject = strSubject
docMail.PostedDate = Now

'=====set body field
Call rtitem.AppendText("Please click this doclink to see more details about the status" + " ")
Call rtitem.AppendDocLink( doc, "click to open document")
Call rtitem.AddNewLine( 2 )

'=====send mail
Call docMail.send(False)
Set doc= docColl.getNextDocument(doc)
Wend

End Sub

Import data from freefile(.txt) to Notes

Sample code used for importing the data from .txt file to notes using LotusScript.

code started from below :

Sub Initialize
        On Error Goto Errhandler
Dim session As New NotesSession
Dim uiws As New NotesUIWorkspace
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim fileName As Variant
Dim counter As Integer
Dim PaintName As String
Dim coatColor As String

Set db= session.CurrentDatabase
fileName= uiws.OpenFileDialog(False,"Test","*.txt","folderlocation")
FileNum% = Freefile()
If Not Isempty(fileName) Then
Open fileName(0) For Input As FileNum%
Do Until Eof(FileNum%)
Input #FileNum%, PaintName, CoatColor
Set doc= db.CreateDocument
With doc
.paintName=PaintName
.CoatColor=CoatColor
End With
Call doc.save(False,False)
counter=counter+1
Loop
End If
Exit Sub
Errhandler:
Msgbox "Error on line number : " & Erl &" Error description : " & Error()
End Sub

Import from Excel to Notes

Sample code used for  importing the data from excel file to notes using LotusScript.

code started from below :

Sub Initialize
Dim session As New notessession
Dim db As NotesDatabase
Dim form As NotesForm
Set db=session.CurrentDatabase
Set form = db.GetForm("FormName")

Dim xlapp As Variant
Dim xlworksheet As Variant
Dim xlsheet As Variant
Set xlapp = CreateObject("Excel.Application")
xlapp.Visible = False
Set xlworksheet = xlapp.Worksheet.Open("pathforfile")
Set xlsheet = xlworksheet.WorkSheet(1)

Dim rows, cols As Integer

xlsheet.Cells.SpecialCells(10).Active
rows= xlsheet.ActiveWindow.ActiveCell.row
Cols = xlsheet.ActiveWindow.ActiveCell.Column

Dim row As Integer
row =0

Do While True
row =row+1
If row = rows+1 Then
Goto Done
End If
If row =1 Then
For i=1 To cols
Redim Preserve fd(i) As String
fd(i) = xlsheet.cells(row,i).value
flag=0
Forall n In form.Fields
If Lcase(fd(i)) = Lcase(n) Then
flag=1
End If
End Forall
If flag=1 Then
Goto skip
End If
If Not flag=1 Then
Msgbox "Field name not appear in the form"
Goto Errhandler
End If

Skip :
Next
End If
If Not row=1 Then
Set doc = db.CreateDocument
doc.Form = formname
For i=1 To cols
Set item= doc.replaceitemvalue(fd(i), xlsheets.Cells(row,i).Value)
Next
End If
Done:
Call xlworksheet.Close
Call xlapp.Quit
Set xlapp=Nothing
Loop
Exit Sub
Errhandler:
Msgbox "Error on Line number : " &Erl() & "Error desc : " &Error()
End Sub