Zadanie skryptowe BPMS (scriptTask)

Domyślna opcja Camundy pozwalająca tworzyć proste, szybkie skrypty, bez konieczności tworzenia handlerów Java/ScriptCode

Dostępne języki to np. Groovy/JavaScript

Dokumentacja

https://docs.camunda.org/manual/7.21/reference/bpmn20/tasks/script-task/

https://docs.camunda.org/manual/7.22/user-guide/process-engine/scripting/

Podpinanie ScriptTask do procesu

Wybieramy Task i podtyp ScriptTask:

  • Format: Język np. Groovy/JavaScript

  • Type: Inline Script

  • Script: skrypt, który chcemy wywołać

Ilustracja 1. Przykład podpięcia ScriptTask w procesie

Popularne metody

execution.getVariable("variableName") - Pobiera zmienną procesu
execution.setVariable("variableName", value) - Ustawia zmienną procesu
execution.removeVariable("variableName") - Usuwa zmienną z procesu
execution.hasVariable("variableName") - Sprawdza czy istnieje zmienna w procesie 
execution.getProcessInstanceId() || execution.getId() - pobiera ID procesu
Ustawnie danych widocznych w Eximee dashboard
    dashboardsParams = [
        "[1]Imię i nazwisko"             : execution.getVariable("clientFullName"),
        "[3]Ogólny typ dyspozycji"       : execution.getVariable("globalCaseTypeName"),
        "[4]Grupa produktowa"            : execution.getVariable("caseGroupName"),
        "[5]Dyspozycja"                  : execution.getVariable("caseTypeName"),
        "[13]Ostatnia osoba procedująca:": execution.getVariable('executorFirstName') +
        " " +
        execution.getVariable('executorLastName') +
        " (" +
        execution.getVariable('executorId') +
        ")"
        ];
 
    if (execution.getVariable("corpFullName") != null) {
        dashboardsParams["[2]Firma"] = execution.getVariable("corpFullName");
        }
 
        dateFormat = "dd.MM.yyyy h:mm"
 
    if (execution.getVariable("startBusinessStatusDate") != null) {
        dashboardsParams["[8]Data rozpoczęcia procesu:"] = execution.getVariable("startBusinessStatusDate").format(dateFormat)
        }
    if (execution.getVariable("tour1BusinessStatusDate") != null) {
        dashboardsParams["[9]Data rozpoczęcia I tury:"] = execution.getVariable("tour1BusinessStatusDate").format(dateFormat)
        }
    if (execution.getVariable("tour2BusinessStatusDate") != null) {
        dashboardsParams["[10]Data rozpoczęcia II tury:"] = execution.getVariable("tour2BusinessStatusDate").format(dateFormat)
        }
    if (execution.getVariable("tour3BusinessStatusDate") != null) {
        dashboardsParams["[11]Data rozpoczęcia III tury:"] = execution.getVariable("tour3BusinessStatusDate").format(dateFormat)
        }
    if (execution.getVariable("endBusinessStatusDate") != null) {
        dashboardsParams["[12]Data zakończenia procesu:"] = execution.getVariable("endBusinessStatusDate").format(dateFormat)
        }
    if (execution.getVariable("sposobWysylki") == "false"){
        dashboardsParams["[14]Sposób wysyłki:"] = "e-mail"
        }
 
execution.setVariable("TASK_DASHBOARD", dashboardsParams);
execution.setVariable("PROCESS_DASHBOARD", dashboardsParams);
Obsługa JSONa w JS
var data = execution.getVariable("kgSymulatorData")
//JSON.parse nie działa w camunda
var cif = S(data).prop("cif").value()
var creditAmount = S(data).prop("creditAmount").value()
var phone =  S(data).prop("phone").value()
var email = S(data).prop("email").value()
 
 
execution.setVariable("cif", cif);
execution.setVariable("creditAmount", creditAmount);
execution.setVariable("phone", phone);
execution.setVariable("email", email);
Zamiana JSON w typie string na typ Object
// Wartość skpToControl -> [{"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)

Więcej informacji o JSON: https://docs.camunda.org/manual/7.7/reference/spin/json/01-reading-json/

Last updated

Was this helpful?