# Script task help

**URL:** <https://forum.flowable.org/t/script-task-help/2757>\
**Category:** Flowable Engine\
**Created:** [October 18, 2018, 6:19pm UTC](https://forum.flowable.org/t/script-task-help/2757 "2018-10-18T18:19:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![markj11](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@markj11](https://forum.flowable.org/u/markj11)\
**Post date:** [October 18, 2018, 6:19pm UTC](https://forum.flowable.org/t/script-task-help/2757/1 "2018-10-18T18:19:40Z")

</div>

I’m trying to put together a simple process to see if flowable is going to work for my needs. I will basically only be using the Modeler and the api’s. The process will set the dueDate, start a timer that will start another process. I’m struggling with script to set the dueDate and I have no logging or debug capabilities.  
this does nothing: execution.setVariable(“dueDate”, “2018-11-17T10:17:43.902+0000”);

the script to start another process works without parameters but doesn’t do anything with parameters:  
this works: runtimeService.startProcessInstanceByKey(“Notification”);  
this doesn’t:  
var notificationParam = new Map();  
notificationParam.set(“notificationRoleId”,-11);  
runtimeService.startProcessInstanceByKey(“Notification”, notificationParam);

---

<div class="post-metadata">

**Author:** ![luisbelloch](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/luisbelloch/32/414_2.png) [@luisbelloch](https://forum.flowable.org/u/luisbelloch)\
**Post date:** [October 18, 2018, 8:57pm UTC](https://forum.flowable.org/t/script-task-help/2757/2 "2018-10-18T20:57:54Z")

</div>

Hi Mark,

by _script_ you mean a groovy _scriptTask_? would you please provide more details on what you’re trying to accomplish?

I’ve included a very simple example of a process using `startProcessInstanceByKey` and passing a `dueDate` variable at the beginning:

```auto
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             xmlns:flowable="http://flowable.org/bpmn"
             targetNamespace="http://www.flowable.org/processdef">
    <process id="dueDatePlayground" name="dueDatePlayground" isExecutable="true">
        <startEvent id="startEvent"/>
        <sequenceFlow sourceRef="startEvent" targetRef="theScriptTask"/>

        <scriptTask id="theScriptTask" name="Execute script" scriptFormat="groovy">
            <script>
                def targetDate = execution.getVariable("targetDate")
                org.slf4j.LoggerFactory.getLogger("theScriptTask").info("targetDate: {}", targetDate)
            </script>
        </scriptTask>
        <sequenceFlow sourceRef="theScriptTask" targetRef="simpleTask"/>

        <userTask id="simpleTask" name="Simple Task" flowable:dueDate="${targetDate}"/>
        <sequenceFlow sourceRef="simpleTask" targetRef="theScriptTask"/>

        <serviceTask id="reporterTask" name="Very simple variable reporter"
                     flowable:class="ReporterTaskDelegate"/>
        <sequenceFlow sourceRef="reporterTask" targetRef="endEvent"/>

        <endEvent id="endEvent"/>
    </process>
</definitions>

```

And the test program you may use to set due dates etc. To run it, simply paste the contents into a text file named `sample.groovy` and run `groovy sample.groovy` from console:

```auto
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.temporal.ChronoUnit

@Grab(group="ch.qos.logback", module="logback-classic", version="1.2.3")
@Grab(group='com.h2database', module='h2', version='1.4.197')
@Grab(group='org.flowable', module='flowable-engine', version='6.4.0-3')
import org.flowable.engine.*
import org.flowable.engine.delegate.DelegateExecution
import org.flowable.engine.delegate.JavaDelegate
import org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration
import org.flowable.engine.runtime.ProcessInstance
import org.flowable.task.api.Task

import org.slf4j.Logger
import org.slf4j.LoggerFactory

class ReporterTaskDelegate implements JavaDelegate {
    void execute(DelegateExecution delegateExecution) {
        Logger logger = LoggerFactory.getLogger(ReporterTaskDelegate.class)
        logger.info("targetDate: {}", delegateExecution.getVariable("targetDate"))
    }
}

ProcessEngineConfiguration processEngineConfiguration = new StandaloneProcessEngineConfiguration()
        .setJdbcUrl("jdbc:h2:mem:flowable;DB_CLOSE_DELAY=-1")
        .setJdbcUsername("sa")
        .setJdbcPassword("")
        .setJdbcDriver("org.h2.Driver")
        .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE)

ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine()
processEngine.getRepositoryService()
        .createDeployment()
        .addClasspathResource('simpleProcess.bpmn20.xml')
        .deploy()

RuntimeService runtimeService = processEngine.getRuntimeService()
LocalDateTime dueDate = LocalDate.now().atStartOfDay().plus(3, ChronoUnit.DAYS);
Map<String, Object> variables = new HashMap<String, Object>()
variables.put("targetDate", dueDate.toString())
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("dueDatePlayground", variables)

TaskService taskService = processEngine.getTaskService()
List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance1.getId()).list()
Task firstTask = tasks.get(0)
LoggerFactory.getLogger("sample").info("dueDate: {}", firstTask.getDueDate())

taskService.complete(firstTask.getId())

```

---

<div class="post-metadata">

**Author:** ![luisbelloch](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/luisbelloch/32/414_2.png) [@luisbelloch](https://forum.flowable.org/u/luisbelloch)\
**Post date:** [October 18, 2018, 9:14pm UTC](https://forum.flowable.org/t/script-task-help/2757/3 "2018-10-18T21:14:26Z")

</div>

I just edited previous sample to include an scriptTask in groovy, that should print in console something like:

```auto
23:10:30.692 [main] INFO theScriptTask - targetDate: 2018-10-21T00:00
23:10:30.851 [main] INFO sample - dueDate: Sun Oct 21 00:00:00 CEST 2018
23:10:30.862 [main] INFO theScriptTask - targetDate: 2018-10-21T00:100

```

If you don’t have access to a debugger, don’t use regular groovy `print` statements, they might not be included in the output.

---

<div class="post-metadata">

**Author:** ![martin.grofcik](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/martin.grofcik/32/71_2.png) [@martin.grofcik](https://forum.flowable.org/u/martin.grofcik)\
**Post date:** [October 19, 2018, 5:42am UTC](https://forum.flowable.org/t/script-task-help/2757/4 "2018-10-19T05:42:51Z")

</div>

Hi Mark.

Try to use process debugger which is part of flowable-task app.  
[https://blog.flowable.org/2018/05/30/process-debugger/](https://blog.flowable.org/2018/05/30/process-debugger/)

you can easily execute and develop scripts there:

Regards  
Martin

---

<div class="post-metadata">

**Author:** ![markj11](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@markj11](https://forum.flowable.org/u/markj11)\
**Post date:** [October 19, 2018, 1:35pm UTC](https://forum.flowable.org/t/script-task-help/2757/5 "2018-10-19T13:35:24Z")

</div>

Thank you for the help. I’m unable to post the xml for some reason.

‘’’\<?xml version="1.0" encoding="UTF-8"?\>  
  
  
  
  
  
PT1M  
  
  
  
  
\<modeler:user-info-email-admin xmlns:modeler=“[http://flowable.org/modeler](http://flowable.org/modeler)”\>\</modeler:user-info-email-admin\>  
\<modeler:user-info-firstname-admin xmlns:modeler=“[http://flowable.org/modeler](http://flowable.org/modeler)”\>\</modeler:user-info-firstname-admin\>  
\<modeler:user-info-lastname-admin xmlns:modeler=“[http://flowable.org/modeler](http://flowable.org/modeler)”\>\</modeler:user-info-lastname-admin\>  
\<modeler:user-info-email-mjones xmlns:modeler=“[http://flowable.org/modeler](http://flowable.org/modeler)”\>\</modeler:user-info-email-mjones\>  
\<modeler:user-info-firstname-mjones xmlns:modeler=“[http://flowable.org/modeler](http://flowable.org/modeler)”\>\</modeler:user-info-firstname-mjones\>  
\<modeler:user-info-lastname-mjones xmlns:modeler=“[http://flowable.org/modeler](http://flowable.org/modeler)”\>\</modeler:user-info-lastname-mjones\>  
\<modeler:activiti-idm-candidate-user xmlns:modeler=“[http://flowable.org/modeler](http://flowable.org/modeler)”\>\</modeler:activiti-idm-candidate-user\>  
\<modeler:initiator-can-complete xmlns:modeler=“[http://flowable.org/modeler](http://flowable.org/modeler)”\>\</modeler:initiator-can-complete\>  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
\<bpmndi:BPMNDiagram id=“BPMNDiagram\_EscalationTimerTestProcess”\>  
\<bpmndi:BPMNPlane bpmnElement=“EscalationTimerTestProcess” id=“BPMNPlane\_EscalationTimerTestProcess”\>  
\<bpmndi:BPMNShape bpmnElement=“startEvent1” id=“BPMNShape\_startEvent1”\>  
\<omgdc:Bounds height=“30.0” width=“30.0” x=“45.0” y=“194.0”\>\</omgdc:Bounds\>  
\</bpmndi:BPMNShape\>  
\<bpmndi:BPMNShape bpmnElement=“sid-B88BF8E9-CEF4-4F7C-9CC1-D8D0AE622DE7” id=“BPMNShape\_sid-B88BF8E9-CEF4-4F7C-9CC1-D8D0AE622DE7”\>  
\<omgdc:Bounds height=“31.0” width=“31.0” x=“139.5” y=“301.0”\>\</omgdc:Bounds\>  
\</bpmndi:BPMNShape\>  
\<bpmndi:BPMNShape bpmnElement=“EscalationTimerTestTask” id=“BPMNShape\_EscalationTimerTestTask”\>  
\<omgdc:Bounds height=“80.0” width=“100.0” x=“285.0” y=“169.0”\>\</omgdc:Bounds\>  
\</bpmndi:BPMNShape\>  
\<bpmndi:BPMNShape bpmnElement=“sid-E65AA760-EDA2-48F4-96AF-3B1C2B4DEC35” id=“BPMNShape\_sid-E65AA760-EDA2-48F4-96AF-3B1C2B4DEC35”\>  
\<omgdc:Bounds height=“28.0” width=“28.0” x=“441.0” y=“195.0”\>\</omgdc:Bounds\>  
\</bpmndi:BPMNShape\>  
\<bpmndi:BPMNShape bpmnElement=“sid-44165A09-B1F1-4F03-8F8C-10C8B0E4D078” id=“BPMNShape\_sid-44165A09-B1F1-4F03-8F8C-10C8B0E4D078”\>  
\<omgdc:Bounds height=“40.0” width=“40.0” x=“135.0” y=“189.0”\>\</omgdc:Bounds\>  
\</bpmndi:BPMNShape\>  
\<bpmndi:BPMNShape bpmnElement=“scriptNotification” id=“BPMNShape\_scriptNotification”\>  
\<omgdc:Bounds height=“80.0” width=“100.0” x=“285.0” y=“276.5”\>\</omgdc:Bounds\>  
\</bpmndi:BPMNShape\>  
\<bpmndi:BPMNShape bpmnElement=“sid-E3311363-3F4D-4C43-BF79-A4F50176FEBB” id=“BPMNShape\_sid-E3311363-3F4D-4C43-BF79-A4F50176FEBB”\>  
\<omgdc:Bounds height=“80.0” width=“100.0” x=“105.0” y=“45.0”\>\</omgdc:Bounds\>  
\</bpmndi:BPMNShape\>  
\<bpmndi:BPMNEdge bpmnElement=“sid-F8B66043-9DFB-4349-B57B-FE67635BE1A3” id=“BPMNEdge\_sid-F8B66043-9DFB-4349-B57B-FE67635BE1A3”\>  
\<omgdi:waypoint x=“384.95000000000005” y=“209.0”\>\</omgdi:waypoint\>  
\<omgdi:waypoint x=“441.0” y=“209.0”\>\</omgdi:waypoint\>  
\</bpmndi:BPMNEdge\>  
\<bpmndi:BPMNEdge bpmnElement=“sid-9A4F4DB4-2F9F-475A-B6D4-8247343C0FF0” id=“BPMNEdge\_sid-9A4F4DB4-2F9F-475A-B6D4-8247343C0FF0”\>  
\<omgdi:waypoint x=“155.0” y=“228.94072955390334”\>\</omgdi:waypoint\>  
\<omgdi:waypoint x=“155.0” y=“301.0”\>\</omgdi:waypoint\>  
\</bpmndi:BPMNEdge\>  
\<bpmndi:BPMNEdge bpmnElement=“sid-7D03D4A1-59A0-490A-AD67-A2D23545DA25” id=“BPMNEdge\_sid-7D03D4A1-59A0-490A-AD67-A2D23545DA25”\>  
\<omgdi:waypoint x=“74.94999797575196” y=“209.0”\>\</omgdi:waypoint\>  
\<omgdi:waypoint x=“135.0” y=“209.0”\>\</omgdi:waypoint\>  
\</bpmndi:BPMNEdge\>  
\<bpmndi:BPMNEdge bpmnElement=“sid-B5F6C802-9757-4A92-BD6A-EEA53BABD451” id=“BPMNEdge\_sid-B5F6C802-9757-4A92-BD6A-EEA53BABD451”\>  
\<omgdi:waypoint x=“170.44999941694144” y=“316.5”\>\</omgdi:waypoint\>  
\<omgdi:waypoint x=“284.99999999986994” y=“316.5”\>\</omgdi:waypoint\>  
\</bpmndi:BPMNEdge\>  
\<bpmndi:BPMNEdge bpmnElement=“sid-FBF0D675-DD39-4203-BDDF-9C189ABD741C” id=“BPMNEdge\_sid-FBF0D675-DD39-4203-BDDF-9C189ABD741C”\>  
\<omgdi:waypoint x=“155.41935483870967” y=“189.41935483870967”\>\</omgdi:waypoint\>  
\<omgdi:waypoint x=“155.16044176706828” y=“124.95”\>\</omgdi:waypoint\>  
\</bpmndi:BPMNEdge\>  
\<bpmndi:BPMNEdge bpmnElement=“sid-9F4F7BBF-9E49-4BAF-811C-32D4E34DCCB9” id=“BPMNEdge\_sid-9F4F7BBF-9E49-4BAF-811C-32D4E34DCCB9”\>  
\<omgdi:waypoint x=“174.9444614103276” y=“209.0”\>\</omgdi:waypoint\>  
\<omgdi:waypoint x=“285.0” y=“209.0”\>\</omgdi:waypoint\>  
\</bpmndi:BPMNEdge\>  
\</bpmndi:BPMNPlane\>  
\</bpmndi:BPMNDiagram\>

---

<div class="post-metadata">

**Author:** ![markj11](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@markj11](https://forum.flowable.org/u/markj11)\
**Post date:** [October 19, 2018, 1:52pm UTC](https://forum.flowable.org/t/script-task-help/2757/6 "2018-10-19T13:52:53Z")

</div>

![flowable](https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex035/uploads/flowable/original/1X/e6db9adc6a311ecd9e08c4270f743a8e88ba3a71.png)
