> For the complete documentation index, see [llms.txt](https://docs.eximee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/scriptcode/dobre-praktyki-scriptcode.md).

# ScriptCode best practices

### Context <a href="#dobrepraktykiscriptcode-kontekst" id="dobrepraktykiscriptcode-kontekst"></a>

The rules for writing ScriptCode on the Eximee platform will help ensure code consistency, readability, and security, and will also make it easier to onboard new employees.

Create ScriptCode according to the rules described below.

<table><thead><tr><th width="206">Area</th><th>Rule</th></tr></thead><tbody><tr><td>Consistent naming convention</td><td><ul><li>Write code in English - use English names for variables, functions, etc.</li></ul><p><strong>Exceptions:</strong> top-down business naming conventions or a high level of script complexity (the decision here is up to the low-code developer). If you decide to use Polish naming convention - <strong>be consistent within a single script</strong>.</p><ul><li>Literal constants <strong>hard-coded</strong> in code, name them in UPPER_SNAKE_CASE format, e.g. <code>const MOBILE_CHANNEL = "mobile"</code></li><li>Name other variables and functions in camelCase format, e.g. const correlationId = context.getFirstParameter('correlationId'), let motherBranchNumber, function generateBranch()</li></ul></td></tr><tr><td>Order in code structure</td><td><p>Organize code according to the following order:</p><ol><li><strong>Literal constants</strong>declare at the beginning of the script</li><li><strong>Variables</strong> then declare variables that will be used in the main logic</li><li><strong>Main logic</strong> the main sequence of operations that the code performs (e.g. data processing, function calls)</li><li><strong>Helper functions</strong> place at the end</li></ol></td></tr><tr><td>Logging</td><td><ul><li>Do not duplicate platform logs - if any parameters are automatically generated by the platform, do not log them again in the script</li><li>Use a sensitive logger to log sensitive data, pattern: <code>Logger.info("Client's PESEL filled in on the form: {}", pesel)</code></li></ul><p><strong>Learn more:</strong><br><a href="/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/scriptcode/logowanie-w-scriptcode.md">Logging in ScriptCode</a></p></td></tr><tr><td>Variable declaration</td><td><ul><li>Do not use var</li><li>Primitive types: use let only when you change the variable's value in the script. In other cases, use const</li><li>Complex types: do not use let if you only modify the content of an object - including arrays (Array), sets (Set), maps (Map).</li></ul><p>There is no need to use let when declaring objects - including arrays (Array), sets (Set), maps (Map) - as long as the reference (that is, the reference to a specific object or array) will not be changed.<br><strong>In most cases, you should use <code>const</code> to declare arrays and other objects, even if their contents will be modified.</strong></p><p>Example using <code>const</code>:</p><pre><code>const array = [1, 2, 3];
array.push(4); // Works correctly, we are modifying the contents of the array
</code></pre><pre><code>const obj = { name: "Alice" };
obj.age = 30; // Works correctly, we are modifying the object's properties

</code></pre><div data-gb-custom-block data-tag="hint" data-style="danger" class="hint hint-danger"><p><strong>Note:</strong> As long as the rhino engine does not properly support block scope for <code>const</code> variables should be declared inside the "for" loop using <code>let</code>. More about the error can be read in the material linked below.<br></p></div><p><strong>Learn more:</strong><br><a href="https://kursjs.pl/kurs/super-podstawy/typy-danych">Data types in Javascript</a>,</p><p><a href="https://www.youtube.com/watch?v=-mbiJ2it-5M">Reference, mutability, primitive types - a refresher on Javascript!</a></p><p><a href="/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/scriptcode/skrypty-scriptservice.md">Scripts(ScriptService)</a></p><p><a href="http://mozilla.github.io/rhino/compat/engines.html">A table listing which functionalities are currently not properly supported by the rhino engine</a><br><a href="https://github.com/mozilla/rhino/issues/326">Rhino: error when declaring const inside for loop</a></p></td></tr><tr><td>Error handling</td><td><ul><li>Use <code>try-catch</code> blocks where exceptions may occur. If an error occurs, log it using the logger to enable easy tracking of the problem.</li></ul></td></tr><tr><td>Code readability</td><td><ul><li>Right-click → select Format Document. This will make the code more clear and readable</li><li>Remove code that is commented out and no longer needed</li><li>Write comments concisely and clearly, explaining more difficult code fragments, intentions, and unusual solutions. Avoid obvious comments that merely repeat what is already readable in the code.</li></ul></td></tr><tr><td>Code repetition</td><td><ul><li>If you repeat a code fragment several times - create a helper function</li></ul></td></tr><tr><td>Script description</td><td><ul><li>When creating a new script/validator - add a description</li></ul></td></tr><tr><td>Tests</td><td><ul><li>Create unit tests whenever possible, including edge cases.</li></ul></td></tr><tr><td>Security</td><td><ul><li>Treat any parameters entering ScriptCode as untrusted when sending to services</li></ul><p><strong>Sample code:</strong></p><p>Wrong:</p><pre><code>const url = "/api/form/" + context.getFirstParameter( "form\_id" ) + "/data" ;
const response = api.rest.v1.get( "host" , {pathParams: url.split( "/" )}); </code></pre><p>Correct:</p><pre><code>const pathParams = \[ "api" , "form" , context.getFirstParameter( "form\_id" ), "data" ];
const response = api.rest.v1.get( "host" , {pathParams: pathParms}); </code></pre><ul><li>Do not use authorization data directly in ScriptCode</li><li>Fetch remote resources (images, documents, card images, etc.) from a trusted source (e.g. eximee platform, bank resource)</li><li>If you need to use any link in the application, make sure it is trusted and that its use directly follows from the requirements</li><li>If a functionality is not available on the platform, report the need - do not use external tools</li></ul><p><strong>Learn more:</strong> <a href="/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/scriptcode/dobre-praktyki-scriptcode/owasp_application_security_verification_standard_4.0-scriptcode.md"><strong>OWASP\_Application\_Security\_Verification\_Standard\_4.0 - scriptCode</strong></a></p></td></tr><tr><td>Mathematical operations with BigDecimal</td><td><ul><li>Perform mathematical operations using BigDecimal</li></ul><p><strong>Learn more:</strong> <a href="/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/scriptcode/skrypty-scriptservice/api-skryptow/operacje-matematyczne-w-scriptcode.md">Mathematical operations in ScriptCode</a></p></td></tr><tr><td>Handling falsy values</td><td><ul><li>Before using a property or method, check whether the variable's value is not <code>null</code> or <code>undefined</code>, to prevent errors related to missing values. In situations where you want to catch also <code>0</code>an empty string or <code>NaN</code>, you can use the general condition <code>if(value)</code>.</li></ul></td></tr><tr><td>Review</td><td><ul><li>If you are not the only low-code developer on the team - ask someone from the team to review the code.</li></ul></td></tr></tbody></table>

### Materials <a href="#dobrepraktykiscriptcode-materialy" id="dobrepraktykiscriptcode-materialy"></a>

* [OWASP\_Application\_Security\_Verification\_Standard\_4.0 - scriptCode](/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/scriptcode/dobre-praktyki-scriptcode/owasp_application_security_verification_standard_4.0-scriptcode.md)
* [Mathematical operations in ScriptCode](/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/scriptcode/skrypty-scriptservice/api-skryptow/operacje-matematyczne-w-scriptcode.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/scriptcode/dobre-praktyki-scriptcode.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
