> 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 consistency, readability, and code safety, as well as make onboarding new employees easier.

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 agreements regarding naming or a high level of script complexity (here the decision is up to the low-code developer). If you decide to use a Polish naming convention - <strong>be consistent within a single script</strong>.</p><ul><li>Literal constants <strong>hardcoded</strong> in code, name them in UPPER_SNAKE_CASE format, e.g. const MOBILE_CHANNEL = "mobile"</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 in 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 performed by the code (e.g. data processing, calling functions)</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 the sensitive logger to log sensitive data, pattern: <a href="http://logger.info/">Logger.info</a>("Client's PESEL filled in on the form: {}", pesel)</li></ul><p><strong>Learn more:</strong><br><a href="/pages/fe49e2a8a7d4c8ca29f58f6943734b089f32f636">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 a variable's value in the script. In other cases, use const</li><li>Composite types: do not use let if you only modify the contents 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 (i.e. the reference to a specific object or array) will not be changed.<br><strong>In most cases, const should be used to declare arrays and other objects, even if their contents will be modified.</strong></p><p>Example using const:</p><p>const array = [1, 2, 3];<br>array.push(4); // Works correctly, we modify the array contents</p><p>const obj = { name: "Alice" };<br>obj.age = 30; // Works correctly, we modify the object's properties<br></p><p><strong>Note:</strong> As long as the Rhino engine does not properly support block scope for const, variables inside a "for" loop should be declared using let. More about the bug can be read in the material linked below.<br></p><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 - Javascript refresher!</a></p><p><a href="/pages/c995d35297f3609a88c181d2f7e2577dde45d4c0">Scripts(ScriptService)</a></p><p><a href="http://mozilla.github.io/rhino/compat/engines.html">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 a for loop</a></p></td></tr><tr><td>Error handling</td><td><ul><li>Use blocks <code>try-catch</code> in places 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 parts of the code, 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, include 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>Bad:</p><p>Good:</p><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. the Eximee platform, a bank resource)</li><li>If you must use any link in the application, make sure it is trusted and its use follows directly from the requirements</li><li>If a functionality is not available on the platform, submit a request - do not use external tools</li></ul><p><strong>Learn more:</strong> <a href="/pages/dc8393d6b23f9a12f11bbf058f8b57eb7e84aa7c"><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="/pages/db1819cb8664baab75f4837c8cdcf1ecb6216f2c">Mathematical operations in ScriptCode</a></p></td></tr><tr><td>Handling falsy values</td><td><ul><li>Before using properties or methods, check whether the variable's value is not <code>null</code> nor <code>undefined</code>, to prevent errors related to missing values. In situations where you want to catch also <code>0</code>, empty string or <code>NaN</code>, you can use a 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.
