CategoryLotus Notes

Lotus Domino/Notes in general and the Lotus Notes client in particular

Computed When Composed

Computed When Composed fields hide a subtlety that may cause troubles. Any CWC field is computed the first time it is added to a document in memory. This certainly happens when the document is composed, but it also happens when an existing document is opened with a form with such a new field.

@Author and @Created

A common mistake in Notes applications is having documents that rely on the @Author and @Created functions to know who created any document and when. These are system functions and for this reason they are unreliable in the context of the application domain. In fact they merely tell who created the Notes document and when, but they don’t say anything about the domain document represented by the Notes document.

It could be argued that if the author and created fields need to hold exactly the values relative to the Notes document, not the domain document, then the @Author and @Created functions do the job. But this is a mistake as well, because their values may change without notice: for example the creation date changes when a document is cut from and pasted again into the database.

So, if a piece of information makes any sense for a document it needs to stay in its own field in the form.

Notes main flexibility is that it’s possible to add new fields at any time. A natural way of adding such two fields to a form is by means of Computed When Composed fields, whose formulas could be @Author and @Created respectively.

Accessing an Oracle table

A Lotus Connector is a powerful means for accessing an Oracle table. To have it work properly, the machine from which the Lotus code is being executed (wether a Domino server for Web operations or a Notes client) needs a working copy of the Oracle client software. The Lotus Conector will simply use some client libraries for accessing the networked database, so the client needs not be running before executing the Lotus code, nor it needs any custom configurations for accessing the database, like any changes to the tnsnames.ora file.

In fact, all of the conection data that would usually go into the tnsnames.ora configuration file, can be much more conveniently stored inside a LotusScript library, like the following

'Connection_Oracle: Option Public Option Declare Const connection_Host = "172.18.32.51" Const connection_Port = "1525" Const connection_SID = "extprd" Const connection_UserId = "Notes Log" Const connection_Password = "Notes Log" Dim connection_Server As String Sub Initialize connection_Server = {} _ & {(DESCRIPTION=} _ & {(ADDRESS_LIST=} _ & {(ADDRESS=} _ & {(PROTOCOL=TCP)(Host=} & connection_Host & {)(Port=} & connection_Port & {)} _ & {)} _ & {)} _ & {(CONNECT_DATA=} _ & {(SID=} & connection_SID & {)} _ & {)} _ & {)} End Sub

Booking a company ID

This is a very simple use of the Lotus Connector clockwork.
There is a SAP application where companies are added to a database using a SAP data entry screen. For some reason, the time at which all the needed data is available, is too far in the future (;-), and some guy needs the company ID as soon as possible, well before the SAP application will provide one.

Behind the scenes, the SAP application returns as a company ID the record ID of that company into the companies Oracle table. Finally that record ID is a value of an Oracle sequence, which is incremented whenever a new record is added to the companies table. So it is possible to book a company ID, simply by incrementing the sequence. This means that no record is added to the database, but that ID is unique and will never be used for any other record.

'BookCompanyID: Option Public Option Declare Uselsx "*LSXLC" Use "Connection Oracle" Function BookCompanyID As Long On Error Goto HandleError Dim session As New LCSession session.ClearStatus Goto Begin HandleError: Dim errmsg As String errmsg = "Error " & Err & Chr$( 10 ) _ & Getthreadinfo( 1 ) & ":" & Erl & Chr$( 10 ) If session.Status <> LCSUCCESS Then errmsg = errmsg & session.GetStatusText Else errmsg = errmsg & Error$ End If Error Err, errmsg Begin: Dim sqlNextval As String sqlNextval = { SELECT SQ_COMPANIES.NEXTVAL FROM DUAL } Dim connection As New LCConnection( "oracle8" ) connection.Server = connection_Server connection.UserId = connection_UserId connection.Password = connection_Password '------------------------------------------------------------------------------------------- connection.Connect Dim fields As New LCFieldList Call connection.Execute( sqlNextval, fields ) Dim nextVal As LCField Set nextVal = fields.Lookup( "NEXTVAL" ) Call connection.Fetch( fields ) BookCompanyID = nextVal.Value( 0 ) Done: connection.Disconnect '------------------------------------------------------------------------------------------- End Function

CRC32

A CRC is a number which is supposed to change accordingly to the string its computed upon. So it can be used to detect if the user made changes to a chosen subset of the fields of a document.

When saving the document, just join the text values of the fields in an ordered manner, then get the CRC of that string and store it as a new field value. When checking the document for changes to those fields, make the string again and get its CRC. If the saved CRC and the one just computed are equal, then you should be reasonably sure that those field values have not changed, but if the CRC does change, then you can be completely sure that those field have changed as well!

A CRC32 class comes with the java.util.zip package, and LS2J can be used to access and use it.

Here is the code for a Java library, name it CRC32 Java

import java.util.zip.CRC32;

public class StringCRC32 {

    public static String StringCRC32 ( String s )
    {
        byte[] b = s.getBytes();

        CRC32 crc = new CRC32();

        for ( int i=0; i

And here is a LS2J wrapper, just for making it simpler to use in LotusScript. It’s a LotusScript library and you should name it CRC32

'CRC32: Option Public Option Declare Use "CRC32 Java" Uselsx "*javacon" Function StringCRC32( aString As String ) As String Dim jSession As JavaSession Set jSession = New JavaSession Dim jClass As JavaClass Set jClass = jSession.GetClass( "StringCRC32" ) StringCRC32 = jClass.StringCRC32( aString ) End Function

Hack 2 needed

I’d like I could use parallel assignment in LotusScript. It’s the britghtest single programming concept I discovered in the past year, studying Ruby and other scripting languages.

It’s fairly symmetrical to the argument passing concept and it really enhances code readability.

© 2017 Notes Log

Theme by Anders NorenUp ↑