Scripts

Scripts are shared pieces of code used by templates. You manage them, switch them on and off and transfer them between environments in one place. The page is available to administrators; open it from the Administration menu using the Scripts tile in the Application management and configuration group.

There are three types of scripts. Each has its own tab:

TabWhat the scripts are for
Scripts (CO)JavaScript for Case Overviews and prints. Loaded in the user's browser.
Scripts (CO React)React components for Case Overviews and prints, such as tabs, tables or a progress bar.
Scripts (Calculations)Shared functions for task calculations in templates, such as connections to external services or exchange rate conversion.

In the template, a task calculation selects which scripts from the Calculations section it uses. For overviews and prints, you can choose Loaded scripts in the task's dynamic conditions; if you select none, all active CO and CO React scripts are loaded.

The screenshot shows the list filtered to active scripts.

No.ElementPurpose
1CloseReturns you to the Administration menu.
2ImportOpens the window for importing scripts from a file.
3Export all activeDownloads a JSON file with all active scripts of all three types. Useful for transferring to another environment.
4Scripts (CO)Tab with scripts for Case Overviews.
5Scripts (CO React)Tab with React scripts.
6Scripts (Calculations)Tab with scripts for calculations.
7AddCreates a new script of the type matching the open tab.
8FilterSaved filters. When a filter is active, the Save filter and Clear filters buttons appear.
9NameScript name. Can be filtered.
10ActiveScript status: Active or Inactive. An inactive script is not loaded anywhere.
11Changed (when)When the script was last changed.
12Row actionsMenu with the Edit and Delete actions.
ActionWhat happens
EditOpens the script detail. Double-clicking the row does the same.
DeleteAfter you confirm Do you really want to delete the script?, the script is permanently deleted and removed from all calculations and prints that used it.
Delete or deactivate
Deletion cannot be undone. If you are not sure whether a template still needs the script, just deactivate it in the detail by clearing the Active checkbox instead.

Script detail

No.ElementPurpose
1BreadcrumbsThe tab from which you opened the detail. Click it to return to the list.
2CloseReturns you to the list. You are offered to save any unsaved changes.
3SaveSaves the script and keeps the detail open.
4Save and closeSaves the script and returns you to the list.
5NameRequired. Must be unique; if it matches an existing name, Script name already exists! is displayed.
6ActiveWhether the script is used. A new script is inactive by default.
7ScriptCode editor with syntax highlighting and function hints. CO and Calculations scripts are formatted automatically when opened.

When you save, the application compiles the code. If the code contains a syntax error, saving fails and an error message is displayed.

The detail of a React script looks the same:

Calculation scripts

The detail of a calculation script also has a code view switch:

No.ElementPurpose
1SourceThe code as you wrote it.
2ES6 syntaxThe code converted to a modern form with async/await, which the application generates on every save.

The code in the ES6 syntax view can be edited. On the first edit, the application asks you to Confirm changes; to continue, you must type ES6 and confirm with Overwrite. A warning is then displayed that the source will be overwritten with the ES6 syntax on save; saving therefore replaces the original code.

Importing scripts

  1. Click Import and drag a JSON file into the window, or click to select it. The file has the same format as the export.
  2. The window shows the scripts divided into CO, CO React and Calculations, along with the number of scripts to import and to activate.
  3. For each group, use the Activate switch to choose whether the imported scripts will be active. Use the Remove button to exclude a group from the import.
  4. Click Import.

Import always creates new scripts and never overwrites anything. If a script with the same name already exists, the new script gets a name with a sequence number, for example Utilities_(1). The import either completes in full or not at all.

Transfer between environments
On the test environment, use Export all active and import the file on production. After the import, deactivate or delete the old versions of the scripts so they are not loaded twice.

Related: Service Console, Logs, Templates.

Archiving

Sequences

Syca (opens in a new tab)

Powered by HelpDocs (opens in a new tab)