LotusScript and Notes Formula Language

Attribute(s)

  • Script vs. @Formulas

    Description

    There is considerable overlap between LotusScript and Notes Formula Language. A developer must know when to use one as opposed to the other.

    Motivation

    Choosing the correct programming language for a certain function will lead to a much more efficient application.

    Example / Details

    In Notes, the developer has the choice of using the following programming
    languages:

    Formula Language
    LotusScript
    HTML
    Java
    JavaScript

    The last three are only useful in the Notes Web environment (although
    JavaScript also runs in the Notes client).
    Formula Language and LotusScript can be used in any environment. There is
    considerable overlap between the two. Many functions can be performed in both
    Formula Language and LotusScript. An important key to designing an efficient
    and user-friendly application is to know when to use each.


    When to use Formula Language.
    Choose formula language when:
    The task being performed can be done with a short formula (e.g. 10 lines of
    code or less). Formulas with a few @Functions are more efficient and faster
    than scripts that provide the same functionality.
    Script is not available for the object element. This would include the
    following:
    - View selection and column formulas
    - Replication formulas
    - Form Design
    - Window Title
    - Section Title
    - Section Access
    - Computed Sub-form
    - Hidden Text
    - Hide when formulas
    - Field Design
    - Default Value
    - Input Translation
    - Input Validation
    - Computed Field Formula
    - Keyword Field Formula
    - SmartIcon
    - SmartIcon Formula

    When to use LotusScript
    Use LotusScript when:
    A task requires iteration or looping.
    Examples include:
    - Importing files
    - Processing documents if a value in the current document has been changed.
    A workflow process is being supported. LotusScript can be used to control the
    workflow process. This is often most effectively done in the QuerySave event,
    where script can be used to performed more complex document processing based on
    values in the current document at the QuerySave event.
    One formula, with a large number of @Functions can best be replaced with a
    script sub-routine. This will be faster and more efficient.
    A large amount of data must be processed. A formula using @Functions to access
    multiple databases or documents will do so via the Notes User Interface.
    LotusScript accesses the data directly and is thus much faster.
    Formulas cannot perform the task required. Examples here are the editing of a
    Rich text field or the editing of an ACL.
    OLE objects are being used.
    C API functions are being called.
    Use is being made of I/O functions. Examples here include creation and editing
    files or launching another program.
    External databases must be accessed. This is also possible through @Formulas
    (@Db functions), but script is much more flexible and offers more possibilities
    in manipulating data from external databases.
    A database must be accessed for which the name is unknown.
    A field must be accessed for which the name is unknown.
    Actions must be initiated when a user enters or leaves a field.
    A database must be created or deleted or a full text index must be deleted.
    RichText fields must be edited.
    Values in related documents require changes upon a change in a specific field
    in one of the documents.
    In addition, LotusScript comes with a debugging functionality which greatly
    facilitates the debugging process. In Formula Language an @Prompt message can
    be used to display values to test the code. However, for complex formulas,
    script is easier to implement and debug. Even so, Formula Language is always
    faster than script for identical code. This should be the overriding
    consideration when designing an application. The faster the performance, the
    greater the user satisfaction.
    The performance of simple actions is similar to that of @Functions.


    Examples

    An example of a script which uses the GetView method to change a small number
    of documents:

    Dim Session as New NotesSession
    Dim View As NotesView
    Dim Doc As NotesDocument
    Set DB = Session.CurrentDatabase
    Set View = DB.GetView('People')
    Set Doc = View.GetDocumentByKey('Davis')

    While Not (Doc Is Nothing)
    lastname$ = doc.LastName(0)
    If lastname$ <> 'Davis' Then End
    Doc.MailServer = 'Server5/Acme/US'
    Call Doc.save(True, True, True)
    Set doc = View.GetNextDocument(Doc)
    Wend


    An example of a script that uses the Search method to edit a larger number of
    documents:

    Dim Session As New NotesSession
    Dim Doc As NotesDocument
    Dim DateTime As New NotesDateTime('12/01/94')

    Set Db = Session.CurrentDatabase
    Set collection = db.Search({@Begins(LastName;'E')}, dateTime, 0 )
    Set doc = collection.GetFirstDocument

    While Not (Doc Is Nothing)
    Doc.MailServer = 'Server5/Acme/US'
    Call Doc.save(True, True, True)
    Set Doc = collection.GetNextDocument(Doc)
    Wend