Using LotusScript Evaluate to save lots and lots of work

Finally a new blog entry and another Show-n-Tell+Thursday. (also tagged : sntt

Sometimes there is a easier and more powerful way to do the process, but you’re just blind to thinking of it. The “Evaluate” function in lotusScript is one of those things, especially when your coding for long periods in just LotuScript. “Evaluate” lets you “Execute a Lotus software application macro.” ( i.e. a Lotus formula string ) and is usually of the form : “resultvariant = Evaluate ( macrostring [ , object ] )”.

One of the confusing things is when the optional “object” is needed. (And if needed, should it be a NotesDocument, a NotesDatabase or something else?) The default help really does not provide enough examples or hint at the power of Evalute.

There are several excellent resources for more examples and information.

One is a Notes Net article from 1998 (R4.5 days), Simplifying your LotusScript with the Evaluate statement, which is still very relevent, and has lots of examples, in addtion to a sample db demo the code (Note: the sample file in the sandbox is a zipped file with NO extension. give it a “.zip” extension when you download). One example is a dblook evalute which runs in about 1/4 of the time of a typical lotusscript GetAllDocumentsByKey and Loop Through (!!).

Tom Duff has a entry from 2004 which is hugly useful : Tips for Working with the LotusScript Evaluate Function.

One thing I do is use the vertical bar character | instead of the double quote ” character around the “macrostring”. (see my example below)

One example almost replaces the need for the code in my earlier Finding out if the current user has a given role, in Lotus Script SnTT – which itself uses a Evaluate(“@UserRoles”).

Dim Doc as NotesDocument   
Dim ReaderAccessFieldContainsAdmin As Variant  
Set Doc = 'set the document to that having a field called ReaderAccessField....    
ReaderAccessFieldContainsAdmin  = Evaluate(|@Contains(ReaderAccessField;"Admin")|, Doc)
If ReaderAccessFieldContainsAdmin(0) = 1 Then ' the field "ReaderAccessField" does contain the value "Admin"
' something...
else something else...
end if

or if you need the Comman Name of a the value stored in the field “MailServer”,

Dim servername as variant
servername  = Evaluate(|@Name([CN];MailServer)|, Doc)   ' the doc being a Person Doc in the NAb
print servername(0)

( you could also do a “Evaluate(|@Name([CN];@userName)|, Doc)” )

also I’ve used :

                Doc.CreatedDateTime = Evaluate(|@Now|)

any other good examples or Evaluate stories? Otherwise, go out there and do less work! 😉

4 Replies to “Using LotusScript Evaluate to save lots and lots of work”

  1. While I have occasionally used evaluate in my LotusScript (espcially with @UserRoles), I try not to use it so much due to it’s performance costs. For that reason, I have really gotten to know the NotesDateTime and NotesName classes.

    Instead of using some of your favorite @Functions via Evaluate, take a look at the Domino Developer Help database for the LotusScript equivalent functions and methods. For example, instead of using Evaluate(|@Now|), use Now instead. And when trying to get the common name of a user or server name, use the notesname.Common attribute.

    The more you are able to use the native LS functions, the better your LS code will be. It will also allow you to transform your LS from procedural code to something that is more object oriented.


  2. If you have to work with complex @formulas, and fields on the doc itself, it sometimes pays to use evaluate.
    However, why, in a examples you mentioned, not just use:

    instead of
    ReaderAccessFieldContainsAdmin=Evaluate(|@Contains(ReaderAccessField;”Admin”)|, Doc)

    instead of
    Evaluate(|@Name([CN];@userName)|, Doc)”,

    or Doc.CreatedDateTime = Now
    instead of
    Doc.CreatedDateTime = Evaluate(|@Now|)

    As much as I love Formula language, Lotusscript can do a lot of stuff too??

  3. Evaluate is a quite good instrument. I have used it e.g. in bigger applications where configuration documents contain formulas to control workflows and so on.

    Unfortunately there are some restrictions e.g. @Prompt() will not work or debugging the formula is not possible.

    So I wrote a LotusScript function which does not have these problems. I added some more nice features. Free download at

    Have fun with it.


  4. item=doc.getfirstitem(”ReaderAccessField”)
    instead of
    ReaderAccessFieldContainsAdmin=Evaluate(|@Contains(ReaderAccessField;”Admin”)|, Doc)

    contains method in LotusScript is intended for text list rather than substring for a text item. Maybe there is where the @contains comes to play.
    But I tried using @contains.. it did not work..

    My code is ..
    Dim pdoc As NotesDocument
    Dim check_body_file As String
    check_body_file = “mobiles”
    Dim x as Variant

    ‘Say I have a field named body_file in my notes document
    x = Evaluate(|@Contains(body_file ; check_body_file)|,pdoc)

    The code cannot be saved with an error message ” Error in Evaluate Macro”

    When I used more common line like..
    x = Evaluate(|@UpperCase(body_file)|, pdoc)
    it went well..

    Is it possible Evaluate method is not meant for @Contains??

Leave a Reply