Script task help

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);

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:

<?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:

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())

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

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.

Hi Mark.

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

you can easily execute and develop scripts there:

Regards
Martin

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”></modeler:user-info-email-admin>
<modeler:user-info-firstname-admin xmlns:modeler=“http://flowable.org/modeler”></modeler:user-info-firstname-admin>
<modeler:user-info-lastname-admin xmlns:modeler=“http://flowable.org/modeler”></modeler:user-info-lastname-admin>
<modeler:user-info-email-mjones xmlns:modeler=“http://flowable.org/modeler”></modeler:user-info-email-mjones>
<modeler:user-info-firstname-mjones xmlns:modeler=“http://flowable.org/modeler”></modeler:user-info-firstname-mjones>
<modeler:user-info-lastname-mjones xmlns:modeler=“http://flowable.org/modeler”></modeler:user-info-lastname-mjones>
<modeler:activiti-idm-candidate-user xmlns:modeler=“http://flowable.org/modeler”></modeler:activiti-idm-candidate-user>
<modeler:initiator-can-complete xmlns: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>

flowable