JavaScript Engine Jint V3
With the launch of FintechOS v24.2, you can switch to Jint v3 JavaScript engine. However, keep in mind that this can trigger a number of mandatory changes that need to be performed by refactoring some existing server automation scripts.
Switching to Jint V3
In Studio, on the System Parameters page, find the sys-workflowengine-type parameter and change its value to Jint V3. Find more details about this in the System Parameter documentation page.
Mandatory changes with Jint v3
Redefine the same variable multiple times in the same script
Mixing let/const and var for re-declaring or updating a global variable was allowed in Jint v2, but is not JavaScript ES6 compliant and not allowed in Jint v3. A variable declared with let/const must be declared only once global/in a code block. For example, the code below does not work with Jint v3:
// this declaration may be in a referenced workflow library
var a = 15;
// do something
const a = 20; // or let a = 20;
This also applies when a variable in declared in a referenced workflow library, not a library accessed with the SDK method importLibrary.
For reference, read the Var, Let, and Const – What's the Difference? article.
You can use the globalThis object to store global variables or to check if a global variable exists before registering one, this object is available in all engine types.
globalThis.a = 15;
// do something
if (typeof globalThis.a == 'undefined') {
globalThis.a = 20;
}
Or you can use var to redeclare or update global variables, so you could replace let/const with var as a quick fix, albeit a dirty one:
// in a workflow library
var a = 15;
// do something
// suppose here was const a= 20;
// change to var instead of const to
// redeclare a variable with the same name in the workflow
var a = 20;
Redeclaring a variable that was declared earlier during the script execution (for example in a workflow library) might generate duplicated code or an unintended behavior. For example, hiding the business meaning of a variable used by other functions. It is recommended not to use variable names declared in workflow libraries or use a prefix for variable name.
This example also falls under the variable redeclaration topic:
function doSomething(paramName) {
// in the function declare a variable with
// the same name as the expected function parameter
let paramName = 15;
// do something
}
The code above is not syntactically correct, but Jint v2 and Jint v3 will execute it (v8 will not). Future versions of Jint v3 might fix this issue, so you should change the code and not declare a variable in the scope of a function with the same name as a parameter.
Using exception message in try/catch
The following code was used prior to v24.2 to access an exception message, it works in v24.2 and above but only if the script engine is set to Jint v2:
try {
// do something that throws an exception
}
catch (e) {
// e is of type string
if(e == 'expected message') {
// do something based on exception message
}
}
For v24.2 with Jint v3 or v8, the code should be refactored as:
try {
// do something that throws an exception
}
catch (e) {
// e is of type object - call new SDK method to get error message as string
var m = getExceptionMessage(e);
if(m == 'expected message') {
// do something based on exception message
}
}
The SDK method setMessage will work when an exception object is passed as parameter and will set the exception message as in Jint v2, so the code below doesn’t need to be changed:
try {
// do something that throws an exception
}
catch (e) {
// e is of type object in Jintv3/v8
setMessage(e);
}