Skip to content

Commit

Permalink
fix: script task - result variable if output mapping exists
Browse files Browse the repository at this point in the history
  • Loading branch information
abdul99ahad committed Dec 16, 2024
1 parent cc76c0d commit 70defbc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/zeebe/extractors/extractResultVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ export default function(options) {

var resultVariable = baseElement.resultVariable;

// Checks if output variable exists, the scope gets redefined
if (processVariables.some(x => x.origin[0] === element && x.scope === containerElement)) {

// result variable will have local scope
containerElement = element;
}

if (resultVariable) {
var newVariable = createProcessVariable(
element,
Expand Down
21 changes: 21 additions & 0 deletions test/zeebe/fixtures/script-task-output.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_14rdixd" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.28.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.6.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:scriptTask id="Task_1">
<bpmn:extensionElements>
<zeebe:script expression="={}" resultVariable="foo" />
<zeebe:ioMapping>
<zeebe:output target="output" />
</zeebe:ioMapping>
</bpmn:extensionElements>
</bpmn:scriptTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="Activity_074uvug_di" bpmnElement="Task_1">
<dc:Bounds x="160" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

20 changes: 20 additions & 0 deletions test/zeebe/spec/ProcessVariablesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,26 @@ describe('zeebe/process variables module', function() {

});


it('should extract only output variables if result variable exists - simple process with script', async function() {

// given
const xml = read('test/zeebe/fixtures/script-task-output.bpmn');

const definitions = await parse(xml);

const rootElement = getRootElement(definitions);

// when
const variables = await getProcessVariables(rootElement);

// then
expect(convertToTestable(variables)).to.eql([
{ name: 'output', origin: [ 'Task_1' ], scope: 'Process_1' },
{ name: 'foo', origin: [ 'Task_1' ], scope: 'Task_1' },
]);
});

});


Expand Down

0 comments on commit 70defbc

Please sign in to comment.