AnsweredAssumed Answered

How to send workflow/task property values to serviceTask activiti:type='shell'

Question asked by ante.blaskovic on Aug 17, 2015
Latest reply on Aug 18, 2015 by ante.blaskovic
I have serviceTask activiti:type="shell" and I need to pass some parameter values to my script,

How to get access or send these values inside my bpmn ?

- workflow description ?
- task id and/or  workflow id ? 

I already tried:

execution.setVariable('putwf_wfName', bpm_workflowDescription);

error: org.alfresco.scripts.ScriptException: 07170037 Failed to execute supplied script: 07170036 ReferenceError: "bpm_workflowDescription" is not defined. (AlfrescoJS#2)

execution.setVariable('putwf_wfName', taskInstance.id);

error: "org.alfresco.scripts.ScriptException: 07170035 Failed to execute supplied script: 07170034 ReferenceError: "taskInstance" is not defined. (AlfrescoJS#3)"


Please help,




<?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:activiti="http://activiti.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.activiti.org/test">
  <process id="echoShellLinux" isExecutable="true">
    <startEvent id="theStart"></startEvent>
    <sequenceFlow id="flow-mystart" sourceRef="theStart" targetRef="shellEcho">
          <extensionElements>
        <activiti:executionListener event="start" class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener">
          <variable name="bpm_workflowDescription" access="read" />
          <activiti:field name="script">
            <activiti:string>
               <![CDATA[logger.log("Here we are !!!");]]>               
               execution.setVariable('wf_dt', 'MyParam1');
               execution.setVariable('putwf_wfName', bpm_workflowDescription);
            </activiti:string>
          </activiti:field>
        </activiti:executionListener>
      </extensionElements>
    </sequenceFlow>
    <serviceTask id="shellEcho" activiti:type="shell">
      <extensionElements>
        <activiti:field name="command">
          <activiti:string><![CDATA[/home/ultra/alfresco/projects/logme.sh]]></activiti:string>
        </activiti:field>
        <activiti:field name="arg1">
          <activiti:expression>${wf_dt}</activiti:expression>
        </activiti:field>       
        <activiti:field name="arg2">
          <activiti:expression>${putwf_wfName}</activiti:expression>
        </activiti:field>
        <activiti:field name="outputVariable">
          <activiti:string><![CDATA[resultVar]]></activiti:string>
        </activiti:field>
      </extensionElements>
    </serviceTask>
    <sequenceFlow id="sequenceFlow-92315e42-3ba1-480e-8788-c57ca217bbe2" sourceRef="shellEcho" targetRef="theTask"></sequenceFlow>
    <userTask id="theTask" name="keep-alive task"></userTask>
    <sequenceFlow id="sequenceFlow-4ab2aa0a-f004-4296-8ead-58d2f0438c25" sourceRef="theTask" targetRef="theEnd"></sequenceFlow>
    <endEvent id="theEnd"></endEvent>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_echoShellLinux">
    <bpmndi:BPMNPlane bpmnElement="echoShellLinux" id="BPMNPlane_echoShellLinux">
      <bpmndi:BPMNShape bpmnElement="theStart" id="BPMNShape_theStart">
        <omgdc:Bounds height="35.0" width="35.0" x="70.0" y="140.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="shellEcho" id="BPMNShape_shellEcho">
        <omgdc:Bounds height="60.0" width="100.0" x="80.0" y="0.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="theTask" id="BPMNShape_theTask">
        <omgdc:Bounds height="60.0" width="100.0" x="230.0" y="0.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="theEnd" id="BPMNShape_theEnd">
        <omgdc:Bounds height="35.0" width="35.0" x="295.0" y="150.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow-mystart" id="BPMNEdge_flow-mystart">
        <omgdi:waypoint x="87.0" y="140.0"></omgdi:waypoint>
        <omgdi:waypoint x="42.0" y="30.0"></omgdi:waypoint>
        <omgdi:waypoint x="42.0" y="30.0"></omgdi:waypoint>
        <omgdi:waypoint x="80.0" y="30.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sequenceFlow-92315e42-3ba1-480e-8788-c57ca217bbe2" id="BPMNEdge_sequenceFlow-92315e42-3ba1-480e-8788-c57ca217bbe2">
        <omgdi:waypoint x="180.0" y="30.0"></omgdi:waypoint>
        <omgdi:waypoint x="192.0" y="30.0"></omgdi:waypoint>
        <omgdi:waypoint x="192.0" y="30.0"></omgdi:waypoint>
        <omgdi:waypoint x="230.0" y="30.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sequenceFlow-4ab2aa0a-f004-4296-8ead-58d2f0438c25" id="BPMNEdge_sequenceFlow-4ab2aa0a-f004-4296-8ead-58d2f0438c25">
        <omgdi:waypoint x="330.0" y="30.0"></omgdi:waypoint>
        <omgdi:waypoint x="342.0" y="30.0"></omgdi:waypoint>
        <omgdi:waypoint x="342.0" y="30.0"></omgdi:waypoint>
        <omgdi:waypoint x="312.0" y="150.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

Outcomes