In my last blog, I made mention fo the many new features being considered for addition to the coming releases of Lotus Notes. Amongst all the material listed it may not have been obvious the extent to which IBM have announced plans for extending the LotusScript language. So for those of you who are LotusScriot developers, the following is a complete list of all the enhancements for lotusScript that I have heard announced so far:- -- End Of List I think there might be a hint there for those of you that have not yet made the bold step into XPage development ;)
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) Thenstatement. 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) Thenstatement1Elsestatement2. 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.
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 :)
Out of the box the Notes client does not support the importing of PDF files into Rich Text fields. However, somewhere between Notes 6.0 and Notes 8.5 the Word import utility was changed so that it could process PDF files. If you take a PDF File or Attachment and save it with a .doc extension then it becomes possible to import a representation of a PDF file into a rich text field using the Word import. It is not a perfect representation but is can often be good enough to meet the needs of some applications.
Note: This can only take place via the Notes Client using the Notes Client Import option, or programattically with LotusScript using the NotesUIDocument.Import() method
E.g. With LotusScript try something like this:-
Try:OnErrorGoto Catch
Set Body = Source.Document.GetFirstItem("Body")Filename$= atfTempDir()+"\attachment.doc"Forall o In Body.EmbeddedObjects
If(o.Type=EMBED_ATTACHMENT)ThenCall o.ExtractFIle(FileName$)Call Source.Import("Microsoft Word",FileName$)EndIfEndForallCall Source.Save()ExitSub
Catch:StopExitSub
Over the years I have given a lot of thought to programming languages, especially as they relate to Lotus Notes development. I blog about it a lot. Yes Nathan I'm hitting them all over the head with a stick again.... I have expressed my frustration at the lack of development of the LotusScript language that is core to so many Notes applications. I have wondered about the lack of penetration of Java into the Notes development world. And lately I have been asking the question why SSJS and do we need yet another programming language in Notes? So just what is the best programming language for Notes? : The Case For LotusScript Some may view me as something of a LotusScript biggot. I love the language and what it allows me to do with Notes. Basic was the first language I ever used. It was so easy to understand I taught myself by simply reading other people's code and experimenting. There was a time when LotusScript was more advanced than Microsoft's VBA but now it has fallen lightyears behind VB.Net. It is popular in Notes because so many people find it (relatively) easy to learn. It is popular because it can be used almost anywhere inside Notes applications (except View selection formulae, hide-when formulae and a few other spots). It is popular because so many applications are already built with LotusScript as its core. And finally with 8.5.1 we have a half-decent editor for LotusScript. : The Case For Java In many ways Java is a superior language to LotusScript. It provides vastly superior support for Object Oriented Programming. It comes with an extensive library (framework). It is also one of the most popular programming languages. Two of the things that have been attributed to holding back Java in Notes (access to Notes UI classes and a decent editor) have both been provided in 8.5.1. And yet..... despite all this I do not expect to see a significant momentum towards Java anytime soon (outside of Eclipse, Expeditor, Plug-In development etc.). : The Case For Server Sided JavaScript This is a completely new language, so why bother given I have all my existing code is in LotusScript, Java, @Commands (or a combination of all three)? Well for one thing it is presently the only language supported directly by XPages. There are ways to execute Java code and even more obscure ways to execute LotusScript code but I don't see these being very practical. So if you wish to develop Xpages you have little choice. And if you don't wish to develop with XPages you have little chance to use SSJS at the moment either! One of the key reasons to consider SSJS is that this seems to be where IBM is investing most of its time and effort on program language development for the forseeable future. But perhaps the most compelling reason (at least for me) is that when all things are said and done SSJS is probably the best match for Lotus Notes than any of the other programming language choices. : Yes you did read that right. The LotusScript flunkie is actually suggesting SSJS may be a better fit for Notes development than his beloved LotusScript. I have done a lot of SSJS programming over the past six weeks and the more I use it the more I like it. I have begun to realize the complexity in using SSJS is not with the SSJS language itself but rather learning to understand the complexities of Xpages. SSJS is not vastly different to LotusScript but it allows me to do things I could only dream about with LS. There are still areas left for improvement but if IBM are focusing on this language there is more chance these will be fixed than any of the 100+ ideas for LS posted on IdeaJam. : One of the key reasons I like JavaScript so much is that it is built on objects (and remember I am an OOP). Until recently I thought it was a weakness that JavaScript was so loosely typed. Now this seems to be such an asset. And this seems to fit in so well with whole Notes concept. Documents as a collection of fields that may or may not be present in any one document and may or may not be of the same data type in every document. Documents copied and pasted en-mass from one database to another (when allowed). Views that may contain a collection of doccuments of different types whose only association may be they share a few fields with the same name (if at all). And yes, love it or hate it there are none of those foreign key constraints that stop me adding whatever document I want to my database. And replicas of each database created just about everywhere just in case... In an ordered world of tightly defined tables with fixed columns, column types, key constraints and nullable fields a tightly structured language such as Java makes perfect sense. And C# with its interfaces, sealed classes, abstract classes, partial classes etc. is well suited to projects with 10+ developers. In the unstructured world of almost anything goes just get the application out the door as quickly as you can Mr/Ms. sole developer, multi-tasking Notes programmer -- a language such as SSJS seems to be an almost perfect fit. And not just for the minority of us who write OOP with Notes. For procedural programmers we have the nifty ability to invoke many of the @Functions as a standard part of SJS language. The bous for SSJS is that it shares the basic syntax with JavaScript, the dominant language for Web client programming. So after a while you get used to placing those braces around all your compound statements and you remember that different casing means a different variable/functions. : To put it simply, there is a reason we have many programming languages. Each has its own style. Each its own strengths (and weaknesses). The style I see in SSJS seems a very natural fit for Notes and a great many (but certainly not all) of the developers who are attracted to Notes. : Of course it is not a clear cut as switching from one language to another. We still have all those legacy apps to maintain. And there is no sign of SSJS being supported in any of the Notes Classic design elements or even agents real soon. So that leaves XPages, and the rub with that is for the Notes client, XPages really does not (yet) offer much outside of a glorified embedded browser (I can see the hate mail on this already!).... But that is today. IBM have already indicated that they plan to extend XPages to provide Notes client control. When they do, that opens up the chances of doing some Notes client development with SSJS. And hopfeully some time soon we will get some sort of clear indication whether or not IBM plan to provide a single programming language that can be used anywhere across the product. Because as much as I now appreciate SSJS I still see little value in investing too much effort into it outside of Web Client or (possibly) dual client applications. Until I can build the majority of my apps with XPages alone or SSJS is supported in all the design elements I need, it is difficult to find a compelling reason to consider using two programming languages (plus some @Commands here and there). So the challenge is very much there for IBM so make some sense with the programming languages it supports. Can IBM afford to let LotusScript slowly die before it has established a viable alternative? Do LotusScript and Notes classic design elements need an extension to make them more like SSJS & XPages to tide us over until the transition is complete? Is it OK that I like hot-dogs without mustard but would still kill for a meat pie with sauce..... : Related Posts Programming Language - Does It Matter? LotusScript v JavaScript Does LotusScript Have A Future LotusScript Revamp (20 Things I'd Like To See)
As many of you many know I have been lucky enough to have the chance to participate in the OpenNTF project to extend the Discussion template. The team includes Niklas Heidloff and Steve Castledine, two of IBM's great application developers. These guys are constantly coming up with great ideas for this project. One of Niklas's contributions was the idea of using video as a medium to communicate some of the ideas we have for the template. Thanks to Niklas it is now occurring to me that video may be one of the missing pieces for one of my other OpenNTF projects, the .Domino Framework. Here is my first video which explains one of the framework's developer tools, the Property Generator and how it can be used in conjunction with the new Eclipse LotusScript Editor to quikcly generate LotusScript classes. So if you haven't yet had a chance to see the new LotusScript editor up close, here's your chance.
Disclaimer: IBM Lotus Notes/Domino and Lotus Notes Traveler 8.5.1 is
prerelease code and there are no guarantees from IBM that the functionality
presented or discussed will be in the final shipping product.
YES FELLOW LOTUSSCRIPT DEVOTEES - THE WAIT IS ALMOST OVER!!! If you are like me and you write lots of LotusScript code you have probably been waiting for a new LotusScript editor more than anything else. With 8.5.1 that long awaited dream comes true. Note: If you are most unlike me and write lots of Java code then you long awaited Java editor is also here but I will leave that for someone better qualified than I to blog about.... The extent to which this new tool will make a difference to you life will largely depend on the style of LotusScript code you write. Object Oriented Programmers (OOP), like me, write almost all their code as classes inside placed in the Declarations module of LotusScript Libraries. As much as 98% of our LS code can be contained in these LS libraries. We have our own weird language with terms like base classes, properties, methods, constructors, event handlers and delegates. It is this style of LS coding that will benefit the most from the new DDE LS Editor. Procedural Programmers strive to build reuseable code using functions and subroutines that are typically stored in LotusScript libraries and/or agents. You too will benefit from the DDE LS Editor but not to the same extent. The third style of LS coding is what I call spaghetti coding. Here the focus is placing code directly in the various events for forms, views, fields, actions etc. Code re usability usually consists of copy/paste from one event to another. This is perhaps the most common style of LS coding and the style that will benefit the least from the new editor. If you code this way almost none of your code is in LS Libraries and the only time you are likley to make use of the new DDE LS Editor is when you code LS Agents. Class Editor For OOP this is a HUGE productivity saver... Some of the LS Libraries in the .Domino Framework have 5,000+ lines of LS code. Prior to 8.5.1 this meant navigating through 5,000+ lines in a single Declarations module. With the new class editor the outline for my library is broken into classes and then into properties and methods (Subs, functions). All the code for each class is shown as a single text stream. They properties/methods are all shown in alphabetical order, regardless of the order they were written. This can be a plus to some and a minus to others. Personally I like it although I would prefer properties are shown first before methods. Color, icons etc are used to convey information such as private versus public, property versus method. Clicking on an entry causes the editor to jump to the declaration for that code element and it is highlighted. Warning: It was previously possible to declare constatnt in the Options section. If you (like me) did this to get at least some of your code out of the declarations section, the DDE LS Editor willmove the constants from Options into Declarations but leave any comment statements behind. It is best to use a non DDE editor to move the constants with the comments manually into Declarations so the comments dont get jumbeled. Error Reporting All LS coders get the benefit of the improve LS error handling. Now you no longer need to do a save before finding out if you have errors in your code. Nor do you have to manually find each and every line reporting an error. As you complete statements the DDE LS Editor places a red line next to each line with an error. You also have the option to save you LS code even if it has errors. complete list of error is shown in an Errors panel that can even be detached and moved to another monitor for your viewing pleasure (especially if your list is as long as mine gets sometimes!) Class Definitions The next killer OOP feature is that the new editor recognizes custom classes. Hover over any declaration and a definition of the datatype or class will appear as a tool tip. If its a custom class it displays information about that class. Press F3 and the editor will take you to the definition of that class. Template & Comment Templates This was a feature I had not been expecting so it was a nice surprise. Notes Preferences now has a section under Domino Designer for LotusScript Editor. In there you can define templates of commonly used code that can be quickly inserted into your code. Comment Template allow you to define documentation for each type of code module that is then automatically inserted each time you create a new module (class, sub, property get etc.). There are a whole host of parameters that can be specified to get the date, developer name, module name etc. inserted in a specific way. I use the LotusScript.Doc standard for comments so now I have an easy way to have this style added automatically to my code saving me heaps of time on one very important, but very dull, task. Other Goodies There are other useful feature...
The ability to auto indent your code
The ability to manually indet entire blocks of code
The ability to turn a line of code into a comment (and undo) via <Ctrl></>
Goto Line <Ctrl><L>
Verdict This is version 1.0.0 of the DDE LS Editor. It is nowhere near as sophisticated as the editor I used for C# (Visual Studio) but it is a great start. It is almost guaranteed to make every LotusScript programmer smile. I was surprised it was developed as an Eclipse component as so far it is the only component of Classic Notes that IBM have shown any signs of migrating to Eclipse. I am hoping this may mean that IBM have plans to use LotusScript in the future for its new wave of design elements (Xpages) or at least are keeping the door open for such a possibility. Whatever the logic I am very thankful that this tool is finally available and simply cant wait until I can use it on a daily basis. Thanks IBM.....
Unfortunately I did not wake up in time for this morning LotusKnows Jam bloggers call. For me 5am meetings can be something of a challenge! So despite missing the call I felt compelled to at least add something on the topic. So how about my top 10 LotusScript Knows... 1) LotusScript knows that not everyone wants to program in Java. 2) LotusScript knows how to exploit the power of the Notes client 3) LotusScript knows it is now under attack from JavaScript 4) LotusScript knows the meaning of the word patience when waiting for its new editor 5) LotusScript knows how to take out the garbage without being told 6) LotusScript knows how to talk with Forms, Views, Folders, Outlines, Agents, Framesets, and Pages 7) LotusScript still knows how to talk with all versions of Notes from 4.0 to Notes 8.5 8) LotusScript knows how to follow the same instructions on both the client and server 9) LotusScript knows it is still the favorite programming language of Notes developers 10) LotusScript knows its full potential is still to be realized
I have been having lots of fun the past 3 weeks using Domino Design 8.5.0. There are LOTS of issues. There is one in particular I would like to bring to the attention of Notes Developers who use LotusScript heavily and have already or will soon migrate to 8.5.0. It seems in the world of Eclipse the NotesUIWorkspace class no longer be relied upon in the same way it could in the past. In particular the CurrentView and CurrentDocument properties of this class can be totally unpredictable. When you use the Notes 8.5 client (especially with Designer running) you will often see the screen flicker, move around, or randomly switch between the Designer client and the Notes client. I have even seen a minimized Designer client reappear on the screen for no apparent reason. Yes, my client is officially haunted!! I am guessing this relates to the way the Notes client interacts with Eclipse and that certain background tasks trigger parts of the clents temporarily gaining focus. If this occurs at the same time as a piece of LotusScript code is using NotesUIWorkspace to gain access to the current view or document then you might end up with nothing, or a reference to something totally unexpected. These errors are random and very hard to reproduce. An application will test occy 99 times and then fail the 100th time with the same test script. If you have the LotusScript debugger running it gets much worse. The debugger seems to make the NotesUIWorkspace lose all sense of where it was at the time the LS code was invoked. e.g. LotusScript code inside a view action whose first line of code is Dim UIW as New NotesUIWorkspace now has no knowledge of the CurrentView. The end result of all this is that code that runs without the LS debugger running no longer runs when the debbugger is running. So if you are trying to debug LS code you may find your code breaks well before you get to the bit you are debugging. The only workaround I have found so far is to try and redesign the code in a way that information about the current NotesUIView or NotuesUIDocument are stored in a variable that is global to the form or view as part of a QueryOpen or similar event that passes in a reference to the source object. This may not always be possible. In that case you may find yourself like me reverting back to print and dialogbox statements as a very primitive alternative to the LS debugger.
It's been a while since I shared some code.... The DominoMemo class was developed as a way of simplifying the code an application requires to produce e-mail notifications. The 1.0.2 version of .Domino Framework will contain a new AppendViewAsTable method that allows an application dveeloper to request a table be added to the body of a memo that shows the data in the view along with doclinks to each document. This is similar to the Copy Selected as Table command and NotesNewsletter class. The method also allows the data embedded to be restricted to a single category in the view. The code is provided below for those that wish to adapt it for their specific needs.
'/** ' * Append the data in a views as a table in the body of the e-mail ' * ' * @param View The view to be appended ' * @param Category Single category of view to be included - Nothing = all rows ' */ Sub AppendViewAsTable(View AsNotesView, Category AsVariant) Dim Column AsNotesViewColumn' Specific column in view Dim ColumnIndex AsInteger' Index of the column being processed Dim Doc AsNotesDocument Dim TableColumn AsInteger Dim DocEntry AsNotesViewEntry' View entry for column being processed Dim NoColumns AsInteger Dim RowIndex AsInteger' Row in table being processed Dim RTNav AsNotesRichTextNavigator' Allows navigation within Rich Text Item containing table Dim TableStyle AsNotesRichTextParagraphStyle Dim TableStyles()AsNotesRichTextParagraphStyle' Styles used to format table Dim ViewNav AsNotesViewNavigator' Navigation of view Dim ViewEntries AsNotesViewEntryCollection' Entries in view Try: OnErrorGoto Catch Redim TableStyles(0) Set TableStyles(0)= Session.CreateRichTextParagraphStyle() TableStyles(0).LeftMargin = 0 TableStyles(0).FirstLineLeftMargin = 0 TableStyles(0).RightMargin = 150 ForColumnIndex%= 0 ToUbound(View.Columns) Set Column = View.Columns(ColumnIndex%) If(Not(Column.IsHidden Or Column.IsCategory Or Column.IsHideDetail))Then NoColumns%=NoColumns%+ 1 RedimPreserve TableStyles(NoColumns%) Set TableStyles(NoColumns%)= Session.CreateRichTextParagraphStyle() TableStyles(NoColumns%).LeftMargin = 0 TableStyles(NoColumns%).FirstLineLeftMargin = 0 TableStyles(NoColumns%).RightMargin = Column.Width* 150 EndIf NextColumnIndex% SelectCaseTypename(Category) Case"STRING","STRING ()" Set ViewNav = View.CreateViewNavFromCategory(Category) Set ViewEntries = View.GetAllEntriesByKey(Category) CaseElse Set ViewNav = View.CreateViewNav