Thursday, May 15, 2008

how to choose folder using lotus script + api

Sometimes we need to choose a folder during our process of development, but special function for this I did not found. Very often we need to choose only folder (for example for saving attaches from documents)

To solve this task we can use Win API 's methods. Here you will see an example of it.


(Declarations)

Const BIF_RETURNONLYFSDIRS = 1
Const BIF_DONTGOBELOWDOMAIN = 2
Const MAX_PATH = 260
Type BrowseInfo
hWndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As String
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type
Declare Function SHBrowseForFolder Lib "shell32" Alias "SHBrowseForFolderA" (lpbi As BrowseInfo ) As Long
Declare Function SHGetPathFromIDList Lib "shell32" Alias "SHGetPathFromIDListA" ( Byval pidList As Long, Byval lpBuffer As String ) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( Byval lpClassName As Any, Byval lpWindowName As Any ) As Long
Main functionFunction ChooseFolder ( dialogPrompt As String ) As String

Dim lpIDList As Long
Dim sBuffer As String * 255
Dim sReturnVal As String
Dim szTitle As String
Dim tBrowseInfo As BrowseInfo

sBuffer = String ( Len ( sBuffer ) , Chr(0) )
szTitle = dialogPrompt
tBrowseInfo.hWndOwner = FindWindow ( "notes", &H0 )
tBrowseInfo.lpszTitle = szTitle
tBrowseInfo.ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
lpIDList = SHBrowseForFolder ( tBrowseInfo )

If ( lpIDList ) Then
SHGetPathFromIDList lpIDList, sBuffer
ChooseFolder = Left ( sBuffer, Instr ( sBuffer, Chr(0) ) - 1)
End If

End Function



Here is the code on button
Sub Click(Source As Button)
Dim w As New NotesUIWorkspace
Dim doc As NotesDocument
Dim folder As String

Set doc = w.CurrentDocument.Document

folder = ChooseFolder("Select directory")

If folder<>"" Then
Call doc.ReplaceItemValue("FolderPath", folder)
Call w.CurrentDocument.Refresh
End If

End Sub

Tuesday, May 13, 2008

how to run several Lotus Notes clients at the same time

Sometimes it is very useful to run several copies of Lotus Notes. Let's say in one client you run agent and in the same time you continue to work. Also it is very useful when you want to work with different servers at the same time with different IDs.

Here is approach how to do it!

1. We have to change the shortcut of notes: instead of launching a file notes.exe, you need to run nlnotes.exe
C: \ Lotus \ Notes \ nlnotes.exe "= C: \ Lotus \ Notes \ notes.ini"
For convenience, you can also rename the shortcut to "Notes 01"
2. Then we have to copy notes folder, for example in the folder C: \ Lotus \ Notes02
3. Modify notes.ini in new copy of Lotus Notes - we should correct the path with C: \ Lotus \ Notes \ to C: \ Lotus \ Notes02 \
4. Copy shortcut to run, it to "Notes 02, and the change the way.
C: \ Lotus \ Notes02 \ nlnotes.exe "= C: \ Lotus \ Notes02 \ notes.ini"
5. By using these shortcuts you can run two copies of lotus notes

If you repeat this, you can run any number of copies.

You can also change the color of notes desktop to don't forget which version you use now...

Wednesday, May 07, 2008

Evaluation of database

Simple example, how we can evaluation of database. Put this code in DatabaseScript on event PostOpen. I would like to see another examples, but I did not find

(Declarations)

Declare Function NEMGetCurrentSubprogramWindow Lib "nnotesws.dll" () As Long
Declare Function NEMStopSubprogramWindow Lib "nnotesws.dll" (Byval hwnd As Long) As Integer
Sub Postopen(Source As Notesuidatabase)
If Cdat("03/15/2009") < Cdat(Today) Then
Dim wHandle As Long
' Get window handle
wHandle = NEMGetCurrentSubprogramWindow
' Close current window
Call NEMStopSubprogramWindow(wHandle)
End If
End Sub

Add on by Olli Kämäräinen
We have to remember about international date, so here a solution how to fix potential problem...

Function MakeDate(dd As String, mm As String, yyyy As String) As Variant

Dim session As New NotesSession
Dim international As NotesInternational
Dim delim As String
Set international = session.International

delim = international.DateSep

If international.IsDateDMY Then
MakeDate = Cdat(dd & delim & mm & delim & yyyy)
'Messagebox "DMY",, "Format of date"
Elseif international.IsDateMDY Then
MakeDate = Cdat(mm & delim & dd & delim & yyyy)
Elseif international.IsDateYMD Then
MakeDate = Cdat(yyyy & delim & mm & delim & dd)
Else
'Messagebox "Unknown",, "Date"
End
End If

End Function

Tuesday, May 06, 2008

How to create PDF from Lotus Notes

I want to show you one of the way how we can create PDF documents from Lotus Notes. I propose to use this package com.lowagie.text
You can download iText®, a JAVA-PDF library
Read more here Generate PDF files from Java applications dynamically

Here is an example that create PDF document.
import lotus.domino.*;
import java.io.FileOutputStream;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Chapter;
import com.lowagie.text.Font;
import com.lowagie.text.List;
import com.lowagie.text.Table;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfWriter;

public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
//create document's object
Document document = new Document();
try {
//create a document
PdfWriter.getInstance(document, new FileOutputStream("c:\\CreatePDFInlotus.pdf"));
//open doc for r/w
document.open();
//add text
document.add(new Paragraph ("Create PDF in Lotus "));
//if error
} catch (DocumentException de) {
System.err.println(de.getMessage()); }

document.close();

} catch(Exception e) {
e.printStackTrace();
}
}
}
Download Project: convert_2_pdf example

Related articles about creating PDF files

Monday, May 05, 2008

Discovering of memory leaks

You may have discovered memory leaks when your Notes client is running a large job or just running an application on your Domino server. The leaks can occur in various places — and the source of the problems may be almost impossible to identify in your code. Here are some undocumented techniques that can help you find code that might be causing memory leaks.
The trick is to know the name of a function call to some internal registers that will return the amount of memory in use. Here are the types of information returned and the function names:

LotusScript Memory Allocated: Lsi_info(50)
LotusScript Memory Allocated from OS: Lsi_info(51)
LotusScript Blocks Used: Lsi_info(52)

Here's a LotusScript code fragment that shows how to use these functions in a foreground agent:

Sub Initialize
Msgbox(" Total LotusScript Memory Allocated: " & (Lsi_info(50)))
Msgbox(" Total LotusScript Memory Allocated from OS: " & (Lsi_info(51)))
Msgbox(" Total LotusScript Blocks Used: " & (Lsi_info(52)))
End Sub

To determine whether a leak exists, you must run this code BEFORE and AFTER the portion of code you want to investigate. If you want to use the above code in a background agent, you must print the results to the LOG.NSF using code like this:

Sub Initialize
Print "Memory Allocated: " & CStr(Lsi_info(50))
Print "Total LotusScript Memory Allocated from OS: " & CStr(Lsi_info(51))
Print "Total LotusScript Blocks Used: " & CStr(Lsi_info(52))
End Sub

If you write the information to a document in a database (for example, your own log facility), be careful because this procedure also consumes some memory, and thus, the BEFORE and AFTER measurements will NOT be equal. Also, because these techniques are undocumented, use them at your own risk, and make sure you have good backups before implementing them.