diff --git a/src/zeebe/extractors/extractResultVariables.js b/src/zeebe/extractors/extractResultVariables.js index f6c4715..2b3dc51 100644 --- a/src/zeebe/extractors/extractResultVariables.js +++ b/src/zeebe/extractors/extractResultVariables.js @@ -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, diff --git a/test/zeebe/fixtures/script-task-output.bpmn b/test/zeebe/fixtures/script-task-output.bpmn new file mode 100644 index 0000000..c81e1e4 --- /dev/null +++ b/test/zeebe/fixtures/script-task-output.bpmn @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/test/zeebe/spec/ProcessVariablesSpec.js b/test/zeebe/spec/ProcessVariablesSpec.js index 64e5401..0f36e4f 100644 --- a/test/zeebe/spec/ProcessVariablesSpec.js +++ b/test/zeebe/spec/ProcessVariablesSpec.js @@ -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' }, + ]); + }); + });