# Script editor

## Script view <a href="#edytorskryptow-widokskryptuedycja" id="edytorskryptow-widokskryptuedycja"></a>

In the main script view the selected version of the script is displayed. The side panel contains buttons that allow you to slide out the script parameters panel, unit tests and logs.

The button to run the script is located on the **Parameters**.

<figure><img src="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2F0TmsJe1PUFNwZGF50Zeh%2Fobraz.png?alt=media&#x26;token=e69a3cb1-113a-4bf2-8614-f3744e20ee25" alt=""><figcaption><p><em><strong>Illustration 1.</strong> Script view with the "Parameters" panel expanded</em></p></figcaption></figure>

## Script editing  <a href="#edytorskryptow-edycjaskryptu" id="edytorskryptow-edycjaskryptu"></a>

Work on the script is possible thanks to the Monaco editor (the editor supports the JavaScript language).

Initially it runs in **read-only**. To start working, click the **Edit script** button located at the end of the navigation bar.

<figure><img src="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2FpDsYRgQPl4rH3dHk8U3r%2Fobraz.png?alt=media&#x26;token=8cc4b5a5-030f-483b-9eb5-bdcd52295c0f" alt=""><figcaption><p><em><strong>Illustration 2.</strong> Script tab</em></p></figcaption></figure>

The instruction "how to write a service script" is located in [Scripts (scriptService)](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/scriptcode/skrypty-scriptservice) and [ScriptCode best practices](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/scriptcode/dobre-praktyki-scriptcode).

## Variables in ScriptCode within a block scope <a href="#edytorskryptow-zmiennewscriptcodewzakresiebloku" id="edytorskryptow-zmiennewscriptcodewzakresiebloku"></a>

The Eximee platform requires that variables in ScriptCode be declared within block scope.

Lack of variable declaration will cause a script error.

## Parameters  <a href="#edytorskryptow-parametryparametry" id="edytorskryptow-parametryparametry"></a>

Modification of parameters also takes place in Monaco (the editor supports JSON notation).&#x20;

On first opening a non-empty script, parameters will be automatically deduced (if possible) from the script content itself.&#x20;

Under the editor there is a button that allows running the script with the parameters provided in the **Test data.**

<figure><img src="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2FZGhTCgC3aErwubzZHQep%2Fimage.png?alt=media&#x26;token=7bd8a94c-556f-42c3-b412-bef8936ff85f" alt=""><figcaption><p><em><strong>Illustration 3.</strong>  Parameters tab</em></p></figcaption></figure>

Parameters filled in the **Test data** section are not part of the script itself and will not be saved in that script version!

## Editing inputs/outputs <a href="#edytorskryptow-edycjawejsc-wyjscio" id="edytorskryptow-edycjawejsc-wyjscio"></a>

Here we can add or remove service script inputs/outputs.&#x20;

Adding or removing an input will also update the runtime parameters, so after removing a parameter we will lose any mapping it had at the connection point.

<figure><img src="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2FG7THbWAG1fnmjd43jtgB%2Fimage.png?alt=media&#x26;token=d832a322-70d0-47c2-a7e7-fa20ca209253" alt=""><figcaption><p><em><strong>Illustration 4.</strong> Inputs/outputs edit fields</em></p></figcaption></figure>

## Script result  <a href="#edytorskryptow-wynikskryptuwynik" id="edytorskryptow-wynikskryptuwynik"></a>

An additional window appears at the bottom of the screen. There we find all information about the executed script:&#x20;

1. Script runtime given in ms.
2. Execution logs of the script in the form of:

   | `[OPERATION_TIME] [OPERATION_TYPE]: Operation text` |
   | --------------------------------------------------- |

   For example:

   | `[14:31:22,976] [GET_DATA]: Called getData("GesCustomComponent1","data") and resulted with data z cc` |
   | ----------------------------------------------------------------------------------------------------- |
3. &#x20;The result of calling the script (in the logs panel), i.e. all values defined as outputs during the creation of the service script in the form KEY : VALUE.<br>

   <figure><img src="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2Fv1eNGJCtvc7hNEAZDzLM%2Fimage.png?alt=media&#x26;token=be3b5bfa-5dcf-444b-9e5d-8de1e2fb069c" alt=""><figcaption><p><em><strong>Illustration 5.</strong>  Script result tab</em></p></figcaption></figure>

## Monaco editor <a href="#edytorskryptow-edytormonacomonaco" id="edytorskryptow-edytormonacomonaco"></a>

The editor used in the project is a full-fledged editor, which means it offers a set of shortcuts that assist writing. List of the most frequently used keyboard shortcuts:&#x20;

* **Ctrl + Shift + I** - code formatting. After writing any fragment it is always worth formatting it; this increases readability and makes work easier.&#x20;
* **Ctrl + Shift + O** - jump to variable/function. This is search on steroids. When scripts grow to sizes that don't fit on one page, it's worth using such shortcuts to move around the code faster.
* **Ctrl + Shift + K** - delete the entire line.
* **Ctrl + F2** - find and replace a specific symbol (function name, variable).
* **Ctrl + G** - go to line.
* **Ctrl + Shift + Alt + Up/Down Arrow** - clone the cursor up/down.&#x20;
* **F1** - list of all available shortcuts and editor options.&#x20;

## Tests <a href="#edytorskryptow-testy" id="edytorskryptow-testy"></a>

The editor has the ability to define [test scenarios](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/scriptcode/testy-jednostkowe-skryptow).

### Errors during test run

If the script contains errors, during a test run such an error will be logged in the console under the editor. The message will contain the reason and the location in the code where the error occurred.

<figure><img src="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2FZFoY32oGd8Olk5TxH1BN%2Fobraz.png?alt=media&#x26;token=1a4bb1b1-77e4-4370-af18-ca5585c48107" alt=""><figcaption><p><em><strong>Illustration 6.</strong> Test run error</em></p></figcaption></figure>
