Skip to main content

A little rant about Rhino 1.7R5 (the "new" Javascript Engine in Service Now)

Since the release of Helsinki, the Service Now Documentation contains this text:
(Screenshot of the Madrid Documentation)
This sounds as if Rhino 1.7R5 was something fancy and new. In fact, Rhino 1.7R5 was released in January 2015. At the time of this writing, this was exactly four years and three months ago. This is not exactly what I would run under the label "Javascript Engine Update".
Especially if you consider that Rhino is the very interface you are programming against in your daily life as a Service Now programmer. Of course, you can also add Java Code, but this is rather rare. Also the statement "You can use modern library code.." is cool - because you will not be able to leverage any post 2016 Javascript features. This starts with very basic things like the  missing let keyword, but also means that there are no promises and other advanced features available.
Also from a security point of view I think it's not justifiable to use such an old library.
Before you ask: Yes, I talked about this with Service Now (in a HI Incident, when I noticed that the call stack in case of an exception behaved like in an old Rhino version). I was told the newer versions of Rhino did not add anything worthwile. I cannot quite follow this argumentation. More likely is that it takes a long time to re-write all the legacy code in modern Javascript.

I had a recent problem with Rhino (but I am not sure if a newer version would have helped). I wrote a simple function to perform search and replace using a regular expression, however, it was not executed correctly. As it it often the case, Stackoverflow was my rescue. Rhino did not treat my string as a Javascript sting, but as a java.lang.String (you can find out about this by using JSUtil.logObject). This class does not implement the .replace() method.
The only way out is to cast the java.lang.String to a Javascript string by using

var strClean = new String(strInput);

Funny enough, the Service Now editor then remarks "Do not use String as a constructor", which is very helpful indeed.

Bottom line: I really hoped the library would be newer in Madrid, but as you see above, this is not the case.

Comments

Popular posts from this blog

How to write JavaScript code efficiently in Service Now

Let's face it: the code editor of Service Now is ... suboptimal. While it offers basic Features like Syntax checking and (minimal) expansion, developers used to modern IDEs like Visual Studio are quickly underhelmed. For me, the most frustrating issue is that every time I save that large script include, I find myself again in the first line, rather than in the one I was just editing. It is infuriating! Also, it completely lacks Features for refactoring code, leaving only good old "Search and Replace" as an option. My editor of choice is Sublime Text , because it has some very powerful Features to offer: It is fast Multi-Select and Edit Decent Code expansion (without the Service Now specific dot-expansion) Automatic Documentation via  DoxyDoxygen A very powerful  Snippet System (Basic) Refactoring via  Javascript Refactor It's clear that this does not solve all Problems, because for example refactoring only takes the current file into account. If Service N...

How to find a Workflow context?

All Service Now Workflows run on one specific record of a table specified when the Workflow is created. Note that there is one Special Table called "Global" that can be used when a single Workflow should be used for more than one table. Each execution of a Workflow is called a "context" and is linked to one specific record, lets say of the sc_req_item table (for Service Request Management). In General, when looking for anything in Service Now, I recommend a look at the data dictionary. When checking "Tables" (just enter sys_db_object.list in the Filter Navigator and hit enter), you see that there are a couple of tables with the prefix wf_ (this is a funny thing in Service Now: the naming convention for tables are not consistent at all. I think one of the reasons is that the system does not allow renaming tables. This would be a cool Feature, but it would require proper refactoring support in the codebase). Anyway, the table you need to look at is...