Basic LotusScript Programming Guide
Basic LotusScript Programming Guide
COURSE
LOTUS SCRIPT
BASIC
Page 1
Curso LotusScript Básico
1.- INTRODUCTION
While the @functions are ideal for coding a simple logic for example, to
the translation or validation of fields, LotusScript provides the ability to create loops,
build 'case' statements, branches, subroutines, etc.
Page 2
Basic LotusScript Course
The hierarchy of LotusScript classes represents the control flow that you follow in the
user interface if you go from the icon of a database to a view, up to a
document and even a specific field within this document. For example, if you are
programming in LotusScript, you would start with the UIWorkspace class and go down
to the UIDocument class that represents the currently open document. Once
Once you have initialized these objects, you will have access to the fields of the document.
The same principle applies if you are programming with the back-end classes of Domino,
what do the objects you might want to work with represent that are not in the
user interface. You would start in the NotesSession class and go down to the class
NotesDatabase and the NotesDocument class, but we will see this in more detail.
in the Domino object model.
Page 3
Basic LotusScript Course
Multi-platform
Object-oriented
Lotus products bring us a series of classes and objects that are available for
LotusScript. Scripts can be written to access and manipulate these objects. The
scripts are handled by events, either an action, clicking on an object or
button, opening a document or a view.
OLE support
Lotus continues to support @functions and LotusScript works well with them.
The Integrated Development Environment for LotusScript (IDE) provides an interface for
create, edit, and debug the scripts, and also review the variables and properties of the
classes. The IDE allows you to write more complex scripts in Notes.
LotusScript Libraries
Functions and class libraries can be created and reused in other applications.
through the USE statement.
Page 4
Basic LotusScript Course
In general, formulas are better for working with the object that the user
is currently working, for example, to give a default value to a field
or to determine the selection criteria for a view. Scripts are best used for
access existing objects, for example, to change a value in a document-based
in values of other documents. The scripts provide some capabilities that the formulas
no dan, like the ability to manipulate rich text fields. The formulas give
a better performance in some situations and are convenient for applications
simple.
When we are asked to decide when to use LotusScript or formulas for a task
determined, usually depends on its complexity. It is necessary to consider
certain things that we detail below.
SmartIcons Formulas
Try to use the following information to help you determine when to use
formulas or LotusScript to perform some programming task in Notes:
Use a formula when there is a @function or @command that performs the task.
Uses LotusScript for complex process control and for loops (version 6 of
Domino already has @formulas to work with loops, however it is usually much more
it is advisable to implement these with LotusScript.
Use LotusScript to perform tasks that the formula language does not support.
Page 5
Basic LotusScript Course
Should I use front-end or back-end classes? Front-end classes use the same
Domino code like the equivalent @commands, so LotusScript will not execute
better than the formulas when these classes are used. The back-end classes without
embargo, they use a different code and perform better than their @functions
equivalents. For example, avoid using the NotesUIDocument class from the front-end to
update many fields. The NotesDocument class of the back-end is
much faster and allows you to assign data types and add new (hidden) fields.
The front-end class allows updating only fields that already exist in the form, and
it allows you to insert only text in the field, as does the
@Command([EditInsertText]). In addition, the front-end classes will not work in
agents programmed to execute by the server, only in agents that run on the
user workstation, for example from the menu.
Page 6
Basic LotusScript Course
A script consists of one or more lines of text called statements. The statements
They are processed sequentially by the compiler. LotusScript interprets the newline character.
line (return of car how the final of a sentence.
Each statement is generally written on one line, but some extend to more than
a line. To continue a single statement over multiple lines, use the dash character
underscore (_) as line continuation character.
For example, the following script shows 2 statements. The first is contained in a
one line and the second in two:
Identifiers
Keywords
Literals and constants
Operators
Identifiers
They are names given to individual elements of the script. Variables, constants and
functions are some of the elements that require a name or identifier.
When creating identifiers, the following rules should be taken into account:
Some classes of Lotus products and OLE classes can define properties or methods.
whose identifiers use illegal characters for LotusScript identifiers. In
in these cases, such characters must be prefixed with a tilde (̃~) to make
that the character is valid.
Example:
Page 7
Basic LotusScript Course
Names do not discriminate between uppercase and lowercase letters. For example, 'NEdad' is the same as
nedad
xyz
i
A_27
FirstLastName
T1234_567
Keywords
They are words that LotusScript reserves for its own use. They have a meaning or
specific function in the LotusScript language. You cannot use these words in
different contexts than those for which they were created. These refer to sentences, functions
predefined, predefined constants, and data types. The keywords 'New' and
'Delete' can be used to name subs (procedures) that you define in the script.
Other keywords are not names but appear in the sentences for example:
'NoCase' or 'Binary'. Some of the operators in LotusScript are reserved words.
like 'Eqv' and 'Imp'.
Literals
They are data values that do not change. The values of literals can be numbers or
chains.
Strings are written in quotes ( " " ), a pair of vertical bars ( | | ) or a pair
of keys ( { } ), but it is most common to use quotes.
Constants
These are names used to represent values that will not change in the scripts.
One might think that a constant is a name we give to a fixed literal value.
Constants are usually used to name values in Spanish or English.
which are understood by the computer.
Constants can be:
Constant Value
NULL It is a special value that represents that the information is
Page 8
Basic LotusScript Course
%Include "[Link]".
Operators
Page 9
Basic LotusScript Course
\ Division of integers
mod Modulo division (remainder)
-, + Subtract, add
Concatenation & String concatenation
Relational =, <>, ><, <, Number and string comparison
(Comparison) <=, =<, >, >=, ‘Igual que’, ‘No igual que’, ‘No igual
=>, Like ["greater than","less than","less than or equal to"]
{"menor o igual que":"less than or equal to","mayor que":"greater than"}
Page 10
Basic LotusScript Course
The basic unit that programs work with is data. Data is another
word for values. Values can be of different types, such as numbers or letters.
The data type of a value helps in LotusScript to identify:
How much memory should be allocated to store and manipulate the value.
What operations can be performed with the value.
In addition, LotusScript recognizes aggregate data types, such as arrays from which
we will talk later. There is also a data type 'Variant', which can be used
to represent any of the other types of non-aggregated data.
The string and numeric data types represent data that has a single value in
any moment. These are known as scalar data types:
Page 11
Basic LotusScript Course
Syntax
Use one of the two methods to declare a variable:
DIM variableName AS data_type
DIM variableName(character suffix)
Example:
Dim address as String
Of interest! The variable 'interes' has been declared as type SINGLE
Assigning data
Once the variable has been defined, use the assignment operator, the symbol
equal (=), to assign data to the variable.
Example:
The following statements show the definition of a variable, assignment of a value
and show it:
Page 12
Basic LotusScript Course
Example:
The following script shows a message box with a Yes button and a No button and returns
a value indicating which button was selected:
To do this, it is necessary for us to know the complete syntax of the MessageBox function.
where we pass each button that we want to be displayed as a parameter to the
function and each button returns a specific integer value, following this table:
Likewise, you can customize the icon that will be displayed in the box with the message,
either to indicate a notice, error, etc.
Page 13
Basic LotusScript Course
Title: It is the string that will appear in the title bar of the message box.
To know which button the user has pressed, we have the following table of values
numeric values for each type of button, which is a numeric value between 1 and 7 that returns the
MessageBox function.
Activity 3
Page 14
Basic LotusScript Course
This activity produces a dialog box that asks the user for information from a
deposit and assign the value to a variable called nDeposit.
Create a button in the formxxxx in the [Link]
2. In the programming panel, enter the following code:
Dim nDeposito as Single
DepositAmount = InputBox("Enter the deposit amount")
MessageBox(nDeposit)
3. To run the script, select Design - Preview in Notes. Then click on the
button that you have created.
Activity 4
2. In the programming panel, enter the following code in the button's click event:
Dim snombre as string
Dim sprofession as string
Page 15
Basic LotusScript Course
Variant type variables give the program a lot of flexibility, as the variables
they can be used differently in different operations. Use the Variants
when you are not sure about the type of data of the values that the program will manipulate.
Note: LotusScript does not have a date or time data type. Variants are
used for date and time operations.
Unless the variants are going to have a real purpose in the script, try not to
to use them for the following reasons:
Variants use more memory than other types of data.
The Variants are processed more slowly.
You can lose track of the data type of the value you are working with when
one or more variables are Variant.
Creating Constants
The name of the constant can be any valid LotusScript identifier. The value
a constant is a literal that is one of the scalar data types; it can also
to be an expression that evaluates to a constant value.
Example:
Page 16
Basic LotusScript Course
Syntax
To include the [Link] file in the script, write the following statement in the
module 'Globals' of the event declarations:
%Include “[Link]”
Note: If the file is located in a directory other than Notes, include the
route.
Activity 5
This activity shows the use of the MessageBox function with button arguments.
and icons to obtain user information using the [Link] file.
Create a button in the formxxxx
2. In the design panel, select the 'Globals' module of the form and the event
'Declarations' to include the code
%Include “[Link]”
Page 17
Basic LotusScript Course
3. In the click event of the button you created, include the following code:
Page 18
Basic LotusScript Course
8- Creation of Comments
Creation of Comments
Example:
The reserved word REM: use this for comments that take up a single line.
The compiler does not process anything on a line that begins with REM.
Example:
Example:
%REM
The first statement in this script declares a variable called snombre. The
The second line assigns the value 'Pablo' to snombre. The third statement displays
the value of snombre.
%ENDREM
Page 19
Basic LotusScript Course
refund rate.
3. Mostrar el resultado del script en un cuadro de mensaje y preceder el mensaje con la
The refund is of
Page 20
Basic LotusScript Course
9- Arrays
Basic Concepts
Array Elements
An array uses a variable name to refer to multiple values of the same type.
stored data in memory. Each value stored as part of an array is assigned
known as 'element'. The elements of the array are referenced using a
index in combination with the variable name. The index identifies an element
specific
of the array.
For example, an element in the array miArray can be referenced as miarray(1).
The following diagram represents an array with seven elements and their indices:
Array limits
Arrays have a predetermined lower bound of zero (0). Unless they are
specify the opposite, the first element of an array called myArray, will be
miArray(0).
Page 21
Basic LotusScript Course
Syntax
DIM array_name(lower_limit TO upper_limit) AS data_type
Example:
To declare an array variable to store the days of the week as 7 elements
string, write the following:
Declare days(1 to 7) as String
The data of the elements of an array are assigned and retrieved in an element base.
to element. The format to assign data to an array element is:
array_name(index) = data
Activity 6
To illustrate the assignment of strings to each element of an array called myDays, make
the following:
Open the formxxxx
2. Create a button and write the following in the Click event:
Declare misDias(1 to 7) as string
misDias(1) = “Domingo”
misDias(2) = “Lunes”
misDias(3) = “Martes”
misDias(4) = “Miércoles”
misDias(5) = “Jueves”
misDias(6) = “Viernes”
misDias(7) = “Sábado”
MessageBox("The third element of misDias contains " & misDias(3))
3. Test the button
Page 22
Basic LotusScript Course
Use it with the following syntax to allocate space in memory for an array:
Syntax
REDIM array_name(limits)
Example
El siguiente ejemplo muestra cómo declarar un array llamado misDias y luego
set your limits using REDIM
Dim myDays() as String
DIM myDays(1 to 7)
Page 23
Basic LotusScript Course
IF Statements
Expressions
Operators
Relational: evaluates the relationship between two operands (>, <, <> and = ) When two
values are compared using these operators, the result of the expression will always be
return TRUE (1) or FALSE (0).
They are used to manipulate string data. There are available for three types of
operations with strings:
or Concatenation (&)
Comparison (relational operations)
Pattern matching operators (Like)
Syntax
The IF ... END IF block has the following syntax:
IF condition THEN
Sentences
[ELSE
Sentences
END IF
The part that is in brackets is optional.
Page 24
Basic LotusScript Course
Activity 7
Page 25
Basic LotusScript Course
Syntax
The following represents the syntax of the SELECT CASE statement
Activity 8
The following activity uses SELECT CASE statements to perform the tests:
Sub Click(Source As Button)
Dim employeeName As String
Dim icodDept As Integer
Dim fechaCont As Variant
Dim info As Variant
Page 26
Basic LotusScript Course
Activity 9
In this activity, we demonstrate the use of the reserved words TO and IS to test the
range of values:
Activity 10
The following shows the use of the Month() and Today() functions in a Select Case.
Dim imes as integer
Dim srespuesta as String
imes = Month(Today)
SELECT CASE imes
Case 1: srespuesta = “Enero”
Case 2: srespuesta = “Febrero”
Case 3: srespuesta = “Marzo”
... (sentences for cases 4 to 12)
END SELECT
MessageBox("We are in the month of " & srespuesta)
Page 27
Basic LotusScript Course
Example
The following example shows a loop that stores values in an array
Dim i as integer
Declare family array from 1 to 7 as String
FOR i = 1 TO 5
familia(i) = Inputbox(“Ingrese los nombres de 5 miembros de su familia:”)
NEXT i
Activity 11
To demonstrate the use of the For ... Next loop, do the following:
Open the form xxxx
2. Create a button and write the following in the Click event
Dim myDays(1 to 7) as String
For i = 1 to 7
misDias(i) = Inputbox(“Ingrese los días de la semana”)
MessageBox('You just entered the day ' & misDias(i))
Next I
3. Test the button.
FORALL statement
This statement repeatedly executes a block of statements for each element in a
array, list or collection. FORALL retrieves or sets all the values stored in a
array, list or collection.
The syntax is as follows:
FORALL variable_reference IN container
Sentences
Page 28
Basic LotusScript Course
END FORALL
Where
variable_referencia: es una variable de referencia para los elementos del array, lista o
collection. In the body of the Forall loop, 'variable_reference' is used to make
reference to each element of the array, list, or collection called 'container'. The
'variable_reference' cannot have a suffix character to indicate the data type.
container: it is the array, list, or collection whose elements you want to process.
Example:
To traverse all the deposits in an array called myDeposits, you could write:
For all deposits in myDeposits
MessageBox(deposits)
End Forall
Activity 12
To demonstrate the use of the Forall statements, we will create an array with values and then
we will set the entire array to 0. Do the following
1. Open the xxxx form
2. Create a button and in the Click event write the following:
Declare an array of 5 integers
array(0) = 7
array(1) = 14
array(2) = 21
For all x in array
x=0
End ForAll
3. Test the button.
DO sentence
This is an indefinite cycle because the number of times is not known in advance.
that a block of operations is executed. This type of statements are executed while
a given condition may be true or until it becomes true.
Page 29
Basic LotusScript Course
Now an example that tests the condition after the loop is executed.
less once.
Syntax
WHILE condition
[sentences]
WEND
Example:
In this example we will set a counter, given a final number provided by the user:
Dim cont as Integer
Dim inum as Integer
Page 30
Basic LotusScript Course
These are used to manipulate the current user interface. They are used for programming.
events and provide access to the Domino object that the user is currently working with. These
they are the most important:
Class Definition
NotesUIWorkspace Represents the current workspace window of Notes.
NotesUIDatabase It represents the database currently in use.
NotesUIView Represents the view currently used.
NotesUIDocument Represents the document that is currently open.
The following objects
they only have events
associated with them
Button It represents a button.
Field Represents a field.
Navigator Represents a guide.
Page 31
Basic LotusScript Course
These objects are used to manipulate Domino data. They do not support any
event or interaction of the user interface. However, objects can be combined.
of the back-end with the front-end in UI scripts. For example, the object
'NotesUIDocument' has a property called 'Document' that gives us access to the
underlying document. These are the most important objects (not included the
related to XML)
Class Definition
NotesSession Represents the Domino environment of the current script, giving
access to environment variables, Domino directories,
information about the connected user, etc
NotesDbDirectory Represent the Domino databases on a server
specific or the workstation.
NotesDatabase Represents a Domino database.
NotesACL Represents the Access Control List (ACL) of a
database.
NotesACLEntry Represents a single entry in the Control List of
Access. An entry can be for a person, group or
server.
NotesAgent Represents an agent.
NotesView Represents a view or folder of a database and gives
access to the documents within it.
NotesViewColumn Represents a column in a view or folder.
NotesDocumentCollection Represents a collection of documents from a database
data, selected according to a specific criterion.
NotesDocument Represents a document in a database.
NotesItem Represents a piece of information in a
document (usually a field). All items in
a document is accessible through LotusScript, without
import what form is being used to display the
document in the user interface.
NotesRichTextItem Represents a rich text item.
NotesRichTextStyle Represents the attributes of the rich text field.
NotesEmbeddedObject Represents embedded objects, linked objects and
attached files.
NotesDateTime Represents a date and time. Allows performing operations.
of comparison and update between dates.
NotesDateRange Contains a range of NotesDateTime. An object of type
NotesDateTime represents a given date and time.
NotesLog Allows actions and errors to be recorded that
take place during the execution of scripts. They can
register the actions and errors in a Notes database
Page 32
Basic LotusScript Course
Page 33
Basic LotusScript Course
There is a hierarchical relationship for Domino objects. The objects higher up in the hierarchy
contain those below. The following figure is an example of the hierarchical relationship between
a few Domino objects:
Each object has defined members, properties, and methods. Using these members,
other objects can be accessed. The content and access relationship means that the
The superior object has the property or method to access the inferior.
For example, all views can be accessed when a database is opened. This
it means that the open database (object) in the workspace includes the views
Even more, you can see the documents when you select one from the view.
This means that your selected view (object) contains the documents (object). This
Hierarchy is important when using Domino objects. NotesSession is the object in the
top of the Domino object model. Any Domino object can be accessed if
it starts from NotesSession.
Now we will see an example of code that uses objects in LotusScript to understand
the movement along the route of the Domino Object Model map:
Example:
Getting the text from the Subject field
Page 34
Curso LotusScript Básico
Set db = [Link]
Set view = [Link]("Todos")
Set doc = [Link]
Set item = [Link]("Subject")
We declare the variables db, view, doc, item as types NotesDatabase, NotesView.
NotesDocumentNotesItem, respectively.
To obtain the text from the Subject field, we need to follow the hierarchical path from the
top to the lowest. In this example, we go from NotesSession to NotesItem.
We initialized the variable db with the CurrentDatabase property of the level object.
superior.
We initialize the variable view using the GetView method, naming the view.
The following statements are the same as the above: we use the methods
GetFirstDocument to obtain the first document from the view and GetFirstItem to
obtain the Subject field of the document.
First, you need to consider how information is stored in Domino. You can think
that a document within a Domino database is a record, but a
Domino document is more sophisticated than a typical database record.
It may contain rich text, images, objects, and other types of information.
For example, if you access a Domino document using the back-end classes, you can
manipulate the content of the fields, add new fields to the document, or delete
fields of the document. However, if you make such changes, the translation formulas
and the validations that exist in the form will not be executed.
On the other hand, if you work with front-end objects, your changes to the fields are
visible to the user. For example, if you invoke the Refresh method of the class
NotesUIDocument, the translation and validation formulas will be executed.
The following figure represents a document in the back-end and shows how the data
are stored in a Domino database:
Page 35
Basic LotusScript Course
The fields Field1 and Field2 have been designed in the form that was used to
create this document. The name of this form is stored in the fieldForm. If
you change the value of the field form using an agent or with LotusScript, the document is
will present the user using the other form when it is opened next time.
The field $UpdatedBy is an internal field created by Domino and contains a list of the
users who have worked with this document.
Observation: Mostly, the fields that start with $ are used and maintained by Domino.
Page 36
Basic LotusScript Course
Activity 9
In this activity, we demonstrate the use of the reserved words TO and IS to test the
range of values:
Activity 10
The following shows the use of the Month() and Today() functions in a Select Case.
Dim imes as integer
Dim srespuesta as String
imes = Month(Today)
SELECT CASE imes
Case 1: srespuesta = “Enero”
Case 2: srespuesta = “Febrero”
Case 3: srespuesta = “Marzo”
... (sentences for cases 4 to 12)
END SELECT
MessageBox("We are in the month of " & srespuesta)
Page 27
Basic LotusScript Course
The NotesView object is one of the most important in Domino because through it
we can access the system documents that ultimately contain
all the information of an application. Therefore, we will see how to navigate through the
documents of a view.
To do this, there are two methods in the NotesView class, which are:
The NotesView object has a large number of properties and methods. For a
Complete description of them, access the Domino Designer help.
Set doc=New NotesDocument(bd) where bd is the object that represents the database
of physical data where the new document created will be stored
Set doc=[Link]()
Set docSig=[Link](doc)
Set doc=[Link]()
Page 38
Basic LotusScript Course
Set docSig=[Link](doc)
In this case, they work the same as when retrieving them from a view. One obtains the
first document and then the rest are obtained sequentially,
starting from the previous one.
Set docAny=[Link](pos)
a) Save
Call [Link](a,b)
The action requires two boolean parameters. (Possible values: true or false)
b) Delete
Call [Link](a)
The parameter will decide whether the document will be deleted even if it has been edited by another.
user at that moment. If true is indicated, the document will be deleted, if indicated
false it will not be saved.
c) Send
Call [Link](a)
The parameter will decide whether the document being sent will include a
form for your viewing. If true is indicated, the document will carry it, if
indicates false it will not take.
Page 39
Basic LotusScript Course
To access the contents of the document (the fields), we must take into account the following
next
Client=[Link](0) This statement loads the content into the variable client
from the field Name that is in the document doc
The NotesDocument object has a large number of properties and methods. For a
complete description of them access the Domino Designer help.
Creation
To create a new NotesDateTime object, you must use the following syntax:
Modification
Existen métodos similares para modificar la parte horaria del objeto nuevaFecha.
Consult the Domino Designer help for more information about
they.
Page 40
Basic LotusScript Course
To compare two dates, the TimeDifference method associated with one of them is used.
them. For example, to compare two date objects, date1 and date2, the syntax
it would be the following:
Difference = [Link](date2)
The execution of this statement returns the difference in seconds that exists
between date1 and date2.
In this case, if date1 is less than date2, the difference will have a negative value.
whereas if it is the other way around, the difference will have a positive value.
If the two dates were identical, the result would be 0.
The object NotesDateTime has a large number of properties and methods. For a
complete description of them access the Domino Designer help.
The NotesUIWorkspace object will be very useful to us when we want to work with the
information we have on screen at any moment
Page 41
Basic LotusScript Course
Call [Link]
To see how to create, edit, or display a UI-End document, review the object
anterior NotesUIWorkspace.
To access the values of a field from a notesUIDocument object we will use the
next syntax:
To modify the values of a field from a notesUIDocument object we will use the
next syntax:
Page 42