Skip to content
This repository was archived by the owner on Aug 24, 2025. It is now read-only.

Execution Flow

Richard Szolár edited this page Dec 17, 2019 · 2 revisions

This page is ought to describe how the execution of scripts work from the perspective of the app and project itself.

Scripts

We can create 1 or n scripts on the Servicenow instance in the Bridge Scripts table. This table will contain all the scripts that run either natively or in a NodeJS enviroment.

You can write your scripts basically anywhere, it must not be in the Servicenow Editor (this does not allow ES6 specific functions and gets crazy for definitions like const or let etc.), you may use the extension from Servicenow to create your script locally and then upload that to the instance or any other tool. This is up to you, the author!

If we would like to run any script, we need the script on the instance (the scoped app installed) and of course the node-exec part of the app, which is basically the execution part. You will need to set this up yourself, there is no free-to-use instance, due to the nature of these scripts and related data, the data may contain confident information which could get exposed if we would run this publicly, so you will have to refer to the Documentation for the node-exec to get you running.

If you are all setup, then you will need to set the "Active" flag on your script and then a "Run Script" button should appear. This button is only visible if the script is Active, to prevent unwanted executions.

Script type

We distinguish two script types:

  • Native
  • NodeJS This can be controlled by the Native checkbox. If checked, the script will run in a native enviroment, which plain simply means in vanilla JS enviroment. This is for simple operations, but since you will most likely not use this at all or very rarely, we don't need to discuss this.

The other mode is the NodeJS mode, which is achieved by unchecking the "Native" checkbox. This will run the script in a NodeJS enviroment. This provides you with many of possibilities. You may require installed npm packages (TODO), builtin NodeJS features and many more. You will need to install the packages manually for the time being on the node-exec instance before running the docker container. (TODO=>samples)

Flow

After initiating the execution of the script an Info Message appears telling you, that the execution was started and that you should look into the "Execution Log" for more information.

There should be a new entry ready, with your script referenced, also a copy with the currently executed script and then an empty "Result" field (if script not Native).

States

We distinguish 3 states for the time being:

  • Sending
  • Processing
  • Complete

Sending is the first state, this is what all created log entries get as a default. The sending state remains up until we get a response (any response) from the node-exec instance. If we get a response, that means that the script is in the state of being processed.

Processing is the state in which the script was successfully sent to the node-exec instance and is being processed. The scripts sent can vary, we can have synchronous or asynchronous scripts which may take some time to get completed. You must wait a bit here. Just make sure, that you had a postback function in your script, so we can get some result from the processing and mark the execution as complete.

Complete is the last stage. Like the name suggests, this is used in the case of the completion of a script on the node-exec instance and successful postback event. So I suggest you use a postback function, see WIKI for more information on this topic.

Now you can do whatever you would like with the result. The result can be anything a base64 encoded file, a string from some crypto library, you can then use this in your scripts on the instance. (TODO=>provide events to react to changes)

This opens a whole new world of scripting to you, you have now the vast amount of NPM packages at your disposal and can use them to create more awesome experience for your customers.

Clone this wiki locally