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