Component Code JS

Description

Executes the JS code specified by the argument in the product layer microservice.

Passes as input either an object with variable values or an object with the specified named arguments.
Any actions can be performed inside the body with application of the passed object in the context of the product layer.
On exit, the returned result is stored in a variable and also, if an object is returned, all its keys are mapped to the existing variables in the script and the values are saved.

Example: "return { a: x + y.name + z[0].caption };" for passed variables or parameters x = "abc", y = {"name": "def"}, z = [{"caption": "ghi"}] will return "abcdefghi" and assign to the existing script variable 'a', and body "{ a: "abcdefghi" }" to the return variable if given.

You can perform an asynchronous query if necessary: "return async function() { await GlobalUtils.wait(500); return { a: 1, b: x }; }".

Table 1. System Characteristics

Index

154

Short title

js

Types of scenarios

All of them

Starter module

era_script_component_js

Mode

Asynchronous

Icon

154

Branching pattern

Branching

Limitations

  • If a timeout is triggered, the script stops waiting for a response and passes control to the next component, the executed method is not terminated.

Properties

Table 2. Properties
Specification Description

Title: Code JS
Code: code
Visibility: no
Default: — 

JS function code to be executed in node.js in a product layer microservice environment.

Title: Parameter setting method
Code: argsMode
Visibility: no
Default: vars

Switches the parameter setting mode for the runtime environment.

Possible values:

  • All variables (allvars,0) - all variables with their values are passed. In JS code you can refer to them directly by their names.

  • Specified arguments (args,1) - the 'Arguments' property specifies a list of named passed parameters. In JS code it is possible to refer to them by the specified names.

When passing JSON string values, representing objects are available in code as objects, JSON arrays are available as arrays, strings and numbers default to strings, dates as a string, and blank values are left blank (null).

Title: Arguments
Code: args
Visibility: yes
Default: — 

List of parameters to be passed and their names.
They can be accessed from executable code via names like normal variables.

If the value is a JSON string with an object or array, the object or array will be accessed directly in the JS code when the corresponding variable is accessed.

Title: Timeout, sec
Code: timeoutSec
Visibility: no
Default: 5

Argument defining the timeout of code execution in the node JS.
When the timeout expires, the script passes control to the 'Transition, timeout' branch and the code continues to execute.

Title: Result to variable
Code: resultVar
Visibility: no
Default: — 

Variable where the full body of the execution result is stored.
If the JS code returns an object or array, its string JSON representation is stored in a variable.

Title: Error to variable
Code: errorVar
Visibility: no
Default: — 

Variable where the string with the error code and text is saved.
Some deployed errors are saved to the log file.

Title: Transition
Code: transfer
Visibility: no
Default: — 

Component to which control is passed.

Title: Transition, Time
Code: transferTimeout
Visibility: no
Default: — 

Component to which control is passed in case of timeout.

Title: Transition, Error
Code: transferError
Visibility: no
Default: — 

The component to which control is passed in case of an error.

See also