Servicenow meets NodeJS
Communicate with a nodejs instance from Servicenow
As a Software developer and user of a vast amount of Open Source projects on a daily basis, there were times, where I had to solve a problem in Servicenow and the first thing that came to my mind was “There must be a ready-made open source project ready for this kind of thing..”.
The thing is, that Servicenow uses Java Rhino for javascript execution on their platform. This is quite limited, so we are not able to use some core Java functions I would assume for security reasons. We are also not really able to run something asynchronously or run ES6 code for instance. This imposes a lot of limits in using modern packages available in the Open Source enviroment.
That is why I was thinking that I would like to be able to run some ready-made npm modules somehow through Servicenow, but with Rhino I was not able to and to load up all pre-compiled dependencies to the platform was also quite unpractical and painful. Some of the packages/modules could be used also through a CDN that’s true, but in a closed enviroments, where some times Firewall rules apply, this is quite unrealistic, to have a user load remote code into their browser.
Also some corporations still using older browsers, which can be incompatible for modern javascript modules, doing this inside the platform is not possible in my opinion.
SNC X NodeJS
This made me thinking, there must be a way to run this somehow outside of Servicenow but still using Servicenow for ease-of-use.
This is when I did think of the idea of a self-hosted NodeJS instance either somewhere inside the corporations network or some remote host, which would be controlled by the individual or company. These could be some boxes, firewalled inside the network and not communicating with the outside world.
To make this as quick as possible, I would suggest to put it on the same network, like Amazon EC2 or something similar, with quick I/O and high quality peering. Using the remote NodeJS instance on the platform will be quite seamless and efficient.
For this reason, I created a simple setup (initial version), that uses vm2 for sandboxing and restify for a simple REST API, which is then used from the Servicenow side. The tests gave quick response time and ease of use.
There is a scoped application ready for you to load up and use it on your platform, although you need to set up the NodeJS instance somewhere, ideally with a public IP so you can connect to it. (set up the sys_property correctly with the URL) and give it a go.
The script include is made simple, there is one function which you need to call, to get the script running defined in the scoped app’s table and then use the result for your needs.
There is a simple logger table present too, this will be always filled with the executed scripts content, result and response. This way you can look up if something went wrong or there are some errors while running the script.
Everything is coupled into an Organsation account on github, follow this blog for updates or the respective github repositories.
I’ve created separate WIKI pages on the repositories, please read them before posting there or asking questions.
And of course I am open to constructive Ideas and criticism, so feel free to open an issue or pull request if you see some space for improvements - which I am sure can be many made at the moment.
See the project: https://github.com/servicenow-node-bridge