Genii Weblog


Civility in critiquing the ideas of others is no vice. Rudeness in defending your own ideas is no virtue.


Mon 3 Feb 2020, 11:16 AM
Posts in this series: 
 
As traditional Notes developers, many of us have mostly steered clear of JavaScript. Others have used JavaScript in the relative safety of XPages. Some have ventured forth into trying out full stack development, but let's face it, the ones who did that successfully mostly left for greener pastures. So, we need to start by quickly looking at JavaScript and Node.js.
 
JavaScript  - For our purposes, JavaScript is a scripting language "for the web", just as LotusScript is a scripting language "for Notes/Domino". JavaScript can be a bit weird for LotusScript developers because it feels so loosey goosey about some things LotusScript is rigid about, and then so rigid about things LotusScript is loose about. A few things to remember:
  • JavaScript treats variables more like Variants, while LotusScript gets more grumpy about shifting type
  • JavaScript is case-sensitive, while LotusScript is not (meaning that true and True and TRUE, as are NotesDatabase and Notesdatabase)
  • Functions in JavaScript can exist anywhere, be nested inside each other, and may not even have names (sorry, you just have to get used to it)
 
If you haven't gotten comfortable with JavaScript, it's time. You simply aren't going to be able to get through life as a professional developer anymore and ignore JavaScript. Take it slowly, there are tons of tutorials, and learn it. You can do it.
 
Node.js - I said JavaScript was a scripting language "for the web", meaning it pretty much exists within a web page. That means a few things, such as always having the DOM (that tree-structured set of windows and such that make up a web page). Well, Node.js is basically an implementation of JavaScript that runs outside of a web container. In fact, odd as it may seem to many of you these days, it inherently starts in what you may think of as a "DOS prompt" or command line. (For Linux people, this is less out of the ordinary.) Node.js is standalone JavaScript. It is fast (written in C++), consistent (JavaScript implementations in different browsers may differ), flexible, and extensible. This last is important, as it is what allows us to build new features into JavaScript.
 
Let's try this! - I'm going to dive in rather than keep defining stuff. If you install the AppDev Pack (more on that installation in another post), you wind up with different pieces in different places. I want to use the latest version, so assume Domino 11 and AppDev Pack 1.0.3, but most of what I say applies to Domino 10 with AppDev Pack 1.0.2.
 
Proton is a Domino server addin. In a production environment that used domino-db on the client, it would also be loaded in the ServerTasks line, but let's load it manually for now. (Console image tweaked so it would fit horizontally.)
 
Inline JPEG image
 
A couple of things to notice. One, this is set up for Anonymous access only. That means I am not using the IAM service yet. That will be a while different post (which I dread). Two, notice that third line says "Listening on 127.0.0.1:51860, INSECURE". That means the server addin is listening on a port, waiting for gRPC messages. The client/server interaction is is via messages sent over a gRPC protocol. Before you get all scared, realize that your regular Notes/Domino client/server interaction isvia messages sent over an NRPC protocol. In other words, this is the same sort of remote procedure call as you are used to, just not quite so hidden by the interface. You can do this.
 
Next, let's write a JavaScript file using domino-db. I'm going to call this trial1.js, and it will use the node-demo.js which is included with the AppDev Pack. The idea behind this is to create a couple of documents on the server using domino-db. Below is an annotated script.
 
Inline JPEG image
 
So, let's try this out.  We have to go to a command line where Node.js is installed, and simply run it. 
 
Inline JPEG image
 
That was unexciting, because it is a command line, and everything is unexciting. But if we open the node-demo.nsf database on the server and take a look, we find the two documents. Here is one, easily distinguished because we only set a couple of fields for Bernard Zelnick.
 
Inline JPEG image
 
We could, of course, have added those other fields. There is also a flag we could have sent which would do a compute with form at the end of the update, useful both for computed fields and for executing input and validation formula. Perhaps an id is required, in which case the validation formula and the entire update would fail. So, there's lots more to explore, but I will leave you with a limitation from the documentation on that JSON payload which will be very important in a couple of subsequent posts.
 
Inline JPEG image
 
If you wanted to include a photo of the person, or a profile with links, or whatever, you couldn't do it easily. Just something to bear in mind.
 
Note: Please ask if you'd like me to focus on any specific aspects. There's a ton of stuff, and I am open to taking on different parts that may be confusing or important or whatever/ Just ask.
 

Copyright © 2020 Genii Software Ltd.

Tags: