Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The internal JavaScript API exposes several objects and functionalities to the executing scripts, enabling them to interact deeply with the system's internal structures. This interaction includes access to persisted concepts in the current context, master data, the current user, and, in specific cases, the potential future state of a concept (for Guard Scripts) or the fields dependent on calculations (for Calculated Fields Scripts).

(warning)External calls - Work in progress

The javascript api will soon have the capability to make authenticated calls to external systems. The authentication method and credentials for different external systems will be defined during system start. This part of the javascript api is yet to be finished. The documentation will be updated when this functionality is available.

Expected Return Values for Guard Scripts

...

  • result2 and concatenatedKey are identifiers used in the calculated fields result.

Making External REST Calls

Scripts can make external REST calls using the webClient object provided by the context. This functionality leverages Spring's WebClient for making HTTP requests (see documentation). This section details how to set up and use the webClient object in your scripts.

Accessing the WebClient

To access the webClient, use the following syntax:

Code Block
languagejs
let webClient = context.getWebClient("GET", "https://host.com/some-uri");
  • Method: The first argument specifies the HTTP method (GET, PUT, POST, DELETE).

  • URI: The second argument is the URI to which the request will be sent.

Authentication and Connection Routing

For authenticated requests, connection routing must be configured for the given URI. If no routing is configured, the web client will make an unauthenticated call. Refer to the connection routing documentation for detailed configuration steps.

Making the Request

To make an actual call, specify the return type and use the webClient as follows:

Code Block
languagejs
let StringClass = Java.type("java.lang.String");
let responseString = webClient.get().uri("https://host.com/some-uri")
                .retrieve()
                .bodyToMono(StringClass)
                .block();

JSON Parsing Example

It is recommended to select String as the return type and then parse the JSON in JavaScript. Here’s how you can parse a JSON response:

Code Block
languagejs
let responseString = webClient.get().uri("https://host.com/some-uri")
                .retrieve()
                .bodyToMono(StringClass)
                .block();

let jsonResponse = JSON.parse(responseString);

// Example of accessing JSON fields
let field1 = jsonResponse.field1;
let field2 = jsonResponse.field2;

console.log("Field 1:", field1);
console.log("Field 2:", field2);

Logging Functionality

Scripts executed within the application have the capability to log messages to the application log, which can be invaluable for debugging and monitoring script execution. This logging is facilitated through the SLF4J logging facade, providing a standardized way to log messages at various levels (e.g., info, debug, error).

...