Inside the body, any actions can be performed using the passed object in the context of the product layer. +\ At the output, the returned result is stored in a variable, and also, if an object is returned, all its keys are compared with the variables available in the script and the values are saved.

Component JS Code

:icons:font :hardbreaks: :imagesdir: ../../../assets/images :toc-title: Contents :toc:

Description

Executes the JS code specified by the argument in the product layer microservice. :description2: Passes as input either an object with the values of the variables or an object with the specified named arguments. +\

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 it to the existing script variable 'a', as well as the body of "{ a: "abcdefghi" }" to the variable returning the result, if specified.

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

Table 1. System characteristics

Index

154

Short name

js

Script types

All

Start module

era_script_component_js

Mode

Asynchronous

Icon

154

Branching type

Branching

Limitations

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

Properties

Table 2. Properties
Specification Description

Name: JS Code

Code: code

Visibility condition: no

Default: — 

JS function code for execution in node.js in a product layer microservice environment.

Name: Method for setting parameters

Code: argsMode

Visibility condition: no Default: vars

Toggles the mode for setting parameters for the runtime environment.

Possible values:

  • All variables (allvars,0) - all variables with their values are transmitted. In JS code, you can access them directly by name.

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

When passing values, JSON strings representing objects are available in the code as objects, JSON arrays are available as arrays, strings and numbers by default, dates are available as a string, and unfilled values remain null.

Name: Arguments

Code: args

Visibility condition: yes

Default: — 

List of passed parameters and their names.

Access to them from the executing code through names as to ordinary variables.

If the value is a JSON string with an object or array, then the JS code will directly access the object or array when accessing the corresponding variable.

Name: Timeout, sec

Code: timeoutSec

Visibility condition: no

Default: 5

Argument defining the code execution timeout in the JS node.

When the timeout expires, the script passes control to the 'Transition, timeout' branch, and the code continues to execute.

Name: Result into variable Code: resultVar Visibility condition: no

Default: — 

Variable where the full body of the execution result is saved.

If the JS code returns an object or array, then the JSON string representation of it is stored in the variable.

Name: Error in variable

Code: errorVar

Visibility condition: no Default: — 

Variable where the string with the error code and text is saved.

Some expanded errors are saved to the log.

Name: Transition

Code: transfer

Visibility condition: no

Default: — 

Component to which control is transferred.

Name: Transition, time

Code: transferTimeout

Visibility condition: no

Default: — 

The component to which control is transferred in case of a timeout.

Name: Transition, error

Code: transferError

Visibility condition: no Default: — 

Component to which control is transferred in case of an error.

See also