Script task not executing

I tried the example given for a script task:

<script>
    def scriptVar = "test123"
    execution.setVariable("myVar", scriptVar)
</script>

I then tried to have the emailtask send me ${myVar} but it failed? if emailtask sends me “test” it works, so I know it’s not the email task… any help would be appreciated.

Thanks!

Hi @Jared

I’ve checked it and it works correctly. Script task sets variable and httptask sends variable value.
Do you see any exception in your logs ?
Can you share your process ?

image
image
I created a script task, put the def and execution in the “script” label
I then sent it out using:
image

Hm…
It’s hard to say what’s going wrong without access to your process.
I don’t know where you create script task and where place httptask. Are both in main process, subprocess, …?
Is it possible that you use it in subprocess and then try to send email from main process ?

Here is my working process (all activities in main process). You can compare it with yours.

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/processdef">
  <process id="mail_sender" name="mail_sender" isExecutable="true">
    <startEvent id="startEvent1"></startEvent>
    <serviceTask id="sid-F5891793-0593-4844-8763-CB5AE48F0792" flowable:type="mail">
      <extensionElements>
        <flowable:field name="to">
          <flowable:string><![CDATA[CHANGEME@email]]></flowable:string>
        </flowable:field>
        <flowable:field name="from">
          <flowable:string><![CDATA[CHANGEME@email]]></flowable:string>
        </flowable:field>
        <flowable:field name="subject">
          <flowable:string><![CDATA[Mail sender test]]></flowable:string>
        </flowable:field>
        <flowable:field name="text">
          <flowable:expression><![CDATA[Test email
myVar -> ${myVar}]]></flowable:expression>
        </flowable:field>
      </extensionElements>
    </serviceTask>
    <endEvent id="sid-7AC00C92-8D7B-49BF-B038-4A719162F042"></endEvent>
    <sequenceFlow id="sid-EF73E679-5BDC-4D0D-8191-C3ABA6310D19" sourceRef="sid-F5891793-0593-4844-8763-CB5AE48F0792" targetRef="sid-7AC00C92-8D7B-49BF-B038-4A719162F042"></sequenceFlow>
    <scriptTask id="sid-C77BB8D2-287D-4728-A8AB-A2323D87EB5C" scriptFormat="groovy" flowable:autoStoreVariables="false">
      <script><![CDATA[def scriptVar = "test123"
execution.setVariable("myVar", scriptVar)]]></script>
    </scriptTask>
    <sequenceFlow id="sid-840B8703-743E-4AB0-A11F-D14282AEA0EB" sourceRef="startEvent1" targetRef="sid-C77BB8D2-287D-4728-A8AB-A2323D87EB5C"></sequenceFlow>
    <sequenceFlow id="sid-AC660BDB-F65F-4948-899A-AC890A967E5F" sourceRef="sid-C77BB8D2-287D-4728-A8AB-A2323D87EB5C" targetRef="sid-F5891793-0593-4844-8763-CB5AE48F0792"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_mail_sender">
    <bpmndi:BPMNPlane bpmnElement="mail_sender" id="BPMNPlane_mail_sender">
      <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
        <omgdc:Bounds height="30.0" width="30.0" x="100.0" y="163.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-F5891793-0593-4844-8763-CB5AE48F0792" id="BPMNShape_sid-F5891793-0593-4844-8763-CB5AE48F0792">
        <omgdc:Bounds height="80.0" width="100.0" x="495.0" y="138.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-7AC00C92-8D7B-49BF-B038-4A719162F042" id="BPMNShape_sid-7AC00C92-8D7B-49BF-B038-4A719162F042">
        <omgdc:Bounds height="28.0" width="28.0" x="765.0" y="161.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-C77BB8D2-287D-4728-A8AB-A2323D87EB5C" id="BPMNShape_sid-C77BB8D2-287D-4728-A8AB-A2323D87EB5C">
        <omgdc:Bounds height="80.0" width="100.0" x="195.0" y="135.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-EF73E679-5BDC-4D0D-8191-C3ABA6310D19" id="BPMNEdge_sid-EF73E679-5BDC-4D0D-8191-C3ABA6310D19">
        <omgdi:waypoint x="594.95" y="178.0"></omgdi:waypoint>
        <omgdi:waypoint x="680.0" y="178.0"></omgdi:waypoint>
        <omgdi:waypoint x="680.0" y="175.0"></omgdi:waypoint>
        <omgdi:waypoint x="765.0" y="175.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-AC660BDB-F65F-4948-899A-AC890A967E5F" id="BPMNEdge_sid-AC660BDB-F65F-4948-899A-AC890A967E5F">
        <omgdi:waypoint x="294.9499999999581" y="175.0"></omgdi:waypoint>
        <omgdi:waypoint x="395.0" y="175.0"></omgdi:waypoint>
        <omgdi:waypoint x="395.0" y="178.0"></omgdi:waypoint>
        <omgdi:waypoint x="494.99999999993634" y="178.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-840B8703-743E-4AB0-A11F-D14282AEA0EB" id="BPMNEdge_sid-840B8703-743E-4AB0-A11F-D14282AEA0EB">
        <omgdi:waypoint x="129.94999191137833" y="178.0"></omgdi:waypoint>
        <omgdi:waypoint x="162.5" y="178.0"></omgdi:waypoint>
        <omgdi:waypoint x="162.5" y="175.0"></omgdi:waypoint>
        <omgdi:waypoint x="194.99999999998522" y="175.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>