> 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/proces-biznesowy/zadania-automatyczne/zadanie-skryptowe-bpms-scripttask.md).

# BPMS script task (scriptTask)

Camunda's default option that allows you to create simple, fast scripts without the need to create Java/ScriptCode handlers.

Available languages include e.g. Groovy/JavaScript.

## Documentation <a href="#zadanieskryptowe-scripttask-camundy-dokumentacja" id="zadanieskryptowe-scripttask-camundy-dokumentacja"></a>

<https://docs.eximeebpms.org/manual/latest/reference/bpmn20/tasks/script-task/>

<https://docs.eximeebpms.org/manual/latest/user-guide/process-engine/scripting/>

## Attaching a ScriptTask to a process <a href="#zadanieskryptowe-scripttask-camundy-podpinaniescripttaskdoprocesu" id="zadanieskryptowe-scripttask-camundy-podpinaniescripttaskdoprocesu"></a>

We choose **Task** and subtype **ScriptTask**:

* Format: Language, e.g. Groovy/JavaScript,
* Type: Inline Script,
* Script: the script we want to invoke.

<figure><img src="/files/70faac35bd88bfc13d27e4b4f56327a4ae5c9acd" alt="" width="347"><figcaption><p><em><strong>Figure 1.</strong> Example of attaching a ScriptTask in a process</em></p></figcaption></figure>

## Common methods <a href="#zadanieskryptowe-scripttask-camundy-popularnemetody" id="zadanieskryptowe-scripttask-camundy-popularnemetody"></a>

```
execution.getVariable("variableName") - Retrieves a process variable
execution.setVariable("variableName", value) - Sets a process variable
execution.removeVariable("variableName") - Removes a variable from the process
execution.hasVariable("variableName") - Checks whether a variable exists in the process 
execution.getProcessInstanceId() || execution.getId() - retrieves the process ID
```

<details>

<summary>Setting data visible in the Eximee dashboard</summary>

```
    dashboardsParams = [
        "[1]First and last name"             : execution.getVariable("clientFullName"),
        "[3]General type of instruction"       : execution.getVariable("globalCaseTypeName"),
        "[4]Product group"            : execution.getVariable("caseGroupName"),
        "[5]Instruction"                  : execution.getVariable("caseTypeName"),
        "[13]Last person handling the case:": execution.getVariable('executorFirstName') +
        " " +
        execution.getVariable('executorLastName') +
        " (" +
        execution.getVariable('executorId') +
        ")"
        ];
 
    if (execution.getVariable("corpFullName") != null) {
        dashboardsParams["[2]Company"] = execution.getVariable("corpFullName");
        }
 
        dateFormat = "dd.MM.yyyy h:mm"
 
    if (execution.getVariable("startBusinessStatusDate") != null) {
        dashboardsParams["[8]Process start date:"] = execution.getVariable("startBusinessStatusDate").format(dateFormat)
        }
    if (execution.getVariable("tour1BusinessStatusDate") != null) {
        dashboardsParams["[9]Start date of round I:"] = execution.getVariable("tour1BusinessStatusDate").format(dateFormat)
        }
    if (execution.getVariable("tour2BusinessStatusDate") != null) {
        dashboardsParams["[10]Start date of round II:"] = execution.getVariable("tour2BusinessStatusDate").format(dateFormat)
        }
    if (execution.getVariable("tour3BusinessStatusDate") != null) {
        dashboardsParams["[11]Start date of round III:"] = execution.getVariable("tour3BusinessStatusDate").format(dateFormat)
        }
    if (execution.getVariable("endBusinessStatusDate") != null) {
        dashboardsParams["[12]Process end date:"] = execution.getVariable("endBusinessStatusDate").format(dateFormat)
        }
    if (execution.getVariable("sposobWysylki") == "false"){
        dashboardsParams["[14]Shipping method:"] = "e-mail"
        }
 
execution.setVariable("TASK_DASHBOARD", dashboardsParams);
execution.setVariable("PROCESS_DASHBOARD", dashboardsParams);
```

</details>

<details>

<summary>Handling JSON in JS</summary>

```
const data = execution.getVariable("kgSymulatorData")
const cif = S(data).prop("cif").value()
const creditAmount = S(data).prop("creditAmount").value()
const phone =  S(data).prop("phone").value()
const email = S(data).prop("email").value()
 
 
execution.setVariable("cif", cif);
execution.setVariable("creditAmount", creditAmount);
execution.setVariable("phone", phone);
execution.setVariable("email", email);
```

</details>

<details>

<summary>Converting JSON from string type to Object type</summary>

```
// skpToControl value -> [{"skp":"198500"},{"skp":"198700"}]
def raw = execution.getVariable("skpToControl")
def parsed = new groovy.json.JsonSlurper().parseText(raw)
 
def list = parsed.collect { item ->
    def m = [:]
    item.each { k, v -> m[k] = v }
    return m
}
 
execution.setVariable("skpObj", list)
```

</details>

More information about JSON: [https://docs.camunda.org/manual/7.7/reference/spin/json/01-reading-json/](https://docs.camunda.org/manual/7.7/reference/spin/json/01-reading-json/?__hstc=218867270.701d355f32e667d247d52b3da539ef04.1729075947404.1729075947404.1729075947404.1&__hssc=218867270.1.1729075947404&__hsfp=456839464#reading-json-properties)


---

# 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/proces-biznesowy/zadania-automatyczne/zadanie-skryptowe-bpms-scripttask.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.
