• Browse Blogs
  • My Blog
  • My Updates

+Tags Get help with tags?

+ Similar Entries

photo

Call DB2 Stored Proc...

Blog:  Ask the Clien...
David J Barry
Updated 
No RatingsRatings 0     No CommentsComments 0
photo

OOP: Part 14 Subform...

Blog:  Beyond The Ye...
Peter Presnell
Updated 
No RatingsRatings 0     CommentsComments 1
photo

Quick Tip: NotesCSEv...

Blog:  Beyond The Ye...
Peter Presnell
Updated 
No RatingsRatings 0     No CommentsComments 0
photo

8.5.1 Fix: GetDocume...

Blog:  Erik Brooks
Erik Brooks
Updated 
RatingsRatings 1     CommentsComments 7
photo

OOP: Part 3 - Wiring...

Blog:  Beyond The Ye...
Peter Presnell
Updated 
No RatingsRatings 0     CommentsComments 1

+ Bookmarks

+ Blog Authors  

Relearning LotusScript

Peter Presnell |   | Tags:  ssjs lotusscript | Comments (2)  |  Visits (1,079)
When I first relocated from Australia to the USA one of the many things I had to learn was driving on the "other" side of the road.  After a while it began to feel natural but then when I returned to Australia for a visit I had to get used to driving on a different side all over again.  The experience is somewhat similar to learning to program SSJS and then returning to LotusScript.  Suddenly I find myself making mistakes with my LotusScript code as a result of trying to use SSJS syntax.
 
What I have found is that there are a few ways to reduce the difference between the syntax of the two languages so that switching  between the two does not cause as many issues.  The following are a few tips to consider when writing LS/SSJS that can reduce the mistakes made when switching between the two languages.  These can also assist when copying code from one to the other:-
 
1) Try/Catch 
 I have blogged about this before.  In SSJS the error handler is always identified by the catch statement.  In LS you can assign any label to to your errorhandler.  So why not use On Error Goto Catch
 
2) If Then Else 
 In SSJS the If condition is enclosed in parentheses.  In LS this is optional - If (condition) Then statement.  So if you get in the habit of doing this with LS code you will be less likely to forget when writing SSJS.  The same can also apply to other LS conditional statements such as While.
 
3) Single Line If 
 If you have a single statement to execute for an if or a single statement for both the if and else it is possible to write this in LS on a single line and drop the End If statement e.g. If (condition) Then statement1 Else statement2.  It is also possible in SSJS to write such statements on a single line.
 
4) Variable Names 
SSJS is case sensitive for many things, INCLUDING variable names.  Most JavaScript developers adopt the practice of using camel casing for variable name (eg. employeeNumber).  With LS variable names are NOT case sensitive.  So consider adopting camel casing for variable names in your LS code to get into the habit.
 
5) Field Names 
In LS field names are somewhat case insensitive.  When creating fields in LS the field name is usually created using the casing provided but it is always possible to access the field using any case.  e.g. I can create a new field on a document with the field name BODY but still access it by doing NotesDocument.GetItemValue("Body").  When writing SSJS the case always seems to matter so it is important to ensure when writing LS code that you use a convention for the casing of field names so that when writing SSJS code you are not left trying to guess what the true field name is.
 
6) Comments 
When writing lengthy comments in LS consider writing them in the format where the comment starts with '/* and ends with ' */.  This provides a degree of consistency with the /* and */ syntax of SSJS.  It also has the added benefit of being consistent with the requirements for using Mikkel Hesiterberg's excellent LotusScript.doc tool to document your LS code.
 
7) Immediate If 
SSJS supports an immediate if statement in the form ((condition) ?truevalue : falsevalue).  LS does not have a native form of this statement.  To get into the habbit of coding using immediate ifs consider creating and immediate if function as part of a standard LS library.
Function IIf(Condition As Boolean,TrueResult As Variant,FalseResult As Variant) As Variant Try: On Error Goto Catch If (Condition) Then If Isobject(TrueResult) Then Set IIF = TrueResult Else IIF = TrueResult Else If Isobject(FalseResult) Then Set IIF = FalseResult Else IIF = FalseResult End If Exit Function Catch: Stop ReportError Nothing Exit Function End Function
8) Debugger 
 And finally, for those of you with sadistic tendencies.  When writing with LS stop using the LS debugger to debug your code.  That way you can endure the same pain we all do when trying to debug our SSJS code :)
No RatingsRatings 0

Comments (2)

photo
1 Karsten Lehmann commented   Permalink No RatingsRatings 0

One of the biggest differences between Lotusscript and Javascript is the fact that JavaScript uses lazy evaluation for if conditions and Lotusscript does not.

 
So for example, this only works in JavaScript:
 
if (arr==null || arr.length==0)
 
 
When arr is null, JavaScript stops after the computation of the part expression part. Lotusscript computes both sides and throws an error. You could always write your Javascript conditions like Lotusscript conditions (e.g. by using nested if's), but you do not really want to do that. :-)
 
There may be good reasons for the Lotusscript (and Basic) way. I don't know any of them. :-)

photo
2 Tim Tripcony commented   Permalink No RatingsRatings 0

Great resource for easing context switching between LS and SSJS...

 
 
 
I dig your IIf function... bit of trivia: this syntax is often referred to as a "ternary" evaluation. And it's one of my favorite constructs in JavaScript... I think because it has all the brevity of a single-line If without the whitespace risks.
 
 
 
I personally haven't encountered issues with field names being case-sensitive in SSJS, but I agree it's best to reinforce the habit of case standardization wherever optional in order to avoid mistakes where it's required.
 
 
 
I have, however, noticed that on the rare occasions where I write LotusScript, I now have to consciously remember not to end each line with a semicolon... although that's optional in JavaScript, I always include it in order to be in the habit when writing Java (which I'm still doing less of than SSJS, but it's rapidly increasing) where it's required. In fact, just yesterday I got a compiler error because I forgot to include "Call" when calling a method... I think it had been years since the last time I saw that error.

Add a Comment Add a Comment

Previous |  Main  | Next
Skip to main content link. Accesskey S
IBM Lotus Connections Help Tools About