Scripts API

Retrieving input data

Below is example code that shows how to use the input and how to return data.

function callService(context){
  const firstArgument = context.getFirstParameter("firstArgument");
  const firstArgumentList = context.getParameters("firstArgument");
  const keySet = context.getInputParameters().keySet();
  const comboboxLabel = context.getData("GesCombobox1","label");
  const result = "service script constant " + firstArgument + " list value: " + firstArgumentList + " and first from list: " + firstArgumentList.get(0) + " keySet " + keySet;
  return [{'output': result}];
}

Input to Service Script

As input (parameter context in the code above) there is an object that provides the following methods:

  • List<String> getParameters(final String name); - retrieves a specific list from the input data map,

  • String getFirstParameter(final String name); - retrieves the first element from a specific list in the input data map or returns the value "null",

  • String getFirstParameter(final String name, final String defaultIfEmpty); - retrieves the first element from a specific list in the input data map, and if it is missing or empty it returns the value "defaultIfEmpty",

  • Map<String, List<String>> getInputParameters(); - returns the entire input data map that it stores,

  • String isVisible(final String id); - retrieves whether the component with the specified id is visible,

  • String getValue(final String id); - retrieves the value of the component (also a session variable) with the specified id,

  • void setValue(final String componentId, final String value); - sets the value value of the component with the specified componentId. The rule for providing componentId is the same as with getValue. When invoking the script inside a composite component, to set the value of a component / session variable embedded in the same component, the componentId must be prefixed with the character @

NOTE! Attempting to perform setValue on a component that listens to another component or on a component on which other components are listening will result in an exception being thrown.

  • String getData(final String id, final String attribute); - retrieves the value of a specific attribute for the component with the specified id

NOTE! Available attributes to retrieve depend on the component.

  • List<Map<String, String>> callService(String name, Map<String, List<String>> input); - allows calling ServiceProxy,

  • ValidatorOutput validate(String name, Map<String, List<String>> input); - allows calling a validator

Output from Service Script

The result of script execution can be returned in two ways:

  1. List of maps - the array of objects at the output is parsed into a list of maps, and then processed in the standard way.

  2. Single map - the return value is wrapped as a single-element list, and then processed in the standard way.

Script output with an example list:

Logging

Logging of input data is automatic

Manual logging should comply with the description in Logging in ScriptCode

Throwing business exceptions

Business errors are described in detail on the page Error pages.

Saving temporary data

It is possible to save some data between service calls. The object used for this is registry.

Possible methods that can be invoked on the registry:

  • save(namespace, id, data) - save data

  • saveVersion(namespace, id, data, version) - save data with version verification. If the version field is unset or empty - save without verification. If the value of the version field does not match the current version of the stored data, the request will end with an error.

  • get(namespace, id) - retrieve data

  • getVersion(namespace, id) - retrieve an object { data: 'saved data', version: 'current data version' }

  • delete(namespace, id) - delete data.

Data is stored in namespaces (namespace in the methods) determined by administrators. Each namespace can have a data time-to-live set. By default it is 90 days. Providing the same id across multiple save calls causes the data associated with that id to be updated. The data version is a unique identifier generated on each data save.

circle-info

The object requires a running EximeeRegistry application to function correctly.

triangle-exclamation

Examples:

Retrieving the context of the logged-in user

circle-exclamation

It is possible to retrieve the context of the currently logged-in user who fills out the request.

chevron-rightAPIhashtag
circle-info

When running the script without a logged-in user context the method context.getSecurityContext() will return the value null

Example usage in a script of the user context

Retrieving application configuration

circle-exclamation
circle-info

The application configuration retrieval functionality is available for scripts (scriptService), script tasks (scriptTask) and validation scripts (validationScript).

In scripts it is possible to retrieve the application configuration

Example script retrieving configuration:

Processing xlsx files

circle-exclamation

It is possible to read xlsx files attached to the request. For this purpose you should use the xlsx-sheet-handling-module and its provided endpoint /xlsx/v1 - the module is currently provided separately, you must perform the appropriate configuration of access to the service in ScriptApi. The module should be given a request:

where in content we pass the file in base64 form. In this form it is passed to the service when we map an uploader to the input (in the case of multiple files in the uploader it is a list). In the response we will receive a map divided as: sheet → row → column

Example:

Retrieving Content of Texts

circle-exclamation

From a script you can retrieve the content of an artifact Text (textContent) created in Eximee Designer, using the function: api.repository.v1.textContent. This function returns an object that has contents for each defined translation. To get the content for a given translation we use the function language. Example usage:

triangle-exclamation

If we are not sure that the parameters we provided are correct, we can handle exceptions using try catch:

Mathematical operations in ScriptCode

More information in Mathematical operations in ScriptCode

Operations and access to process data

More information in Operations and access to process data

Retrieving request statuses

More information in Retrieving request statuses

Data model

More information in Data model API

Other examples

Populating the Combobox (Value selection from list) component

The script populates Value selection field from a list (Combobox) based on the provided 'locale' parameter.

Outputs id, label, and description should be connected to the appropriate combobox fields, respectively id, text, and description.

Script populating the combobox:

Retrieving file names from the Attachments component

The script uses the method getData(), which retrieves the value of a specific attribute for the component with the specified id. For the Attachments component, the names of added files are specified using the attribute fileNames and arrive from the request as a string in JSON format (e.g. ["name1.png", "name2.png"]), therefore it is necessary to transform this string into an object using the method JSON.parse.

circle-exclamation

Retrieving the value of a Combobox from a repeatable section

The script uses the method getData(), which retrieves the value of a specific attribute for the component with the specified id. For the component Combobox the values (labels) of given keys are specified using the attribute label.

Last updated

Was this helpful?