Skip to content

Commit

Permalink
fix: script resultVariable on priority when script and input co-exist
Browse files Browse the repository at this point in the history
  • Loading branch information
abdul99ahad committed Dec 16, 2024
1 parent 8be0558 commit 221d6ea
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 38 deletions.
42 changes: 5 additions & 37 deletions lib/zeebe/VariableResolver.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { getProcessVariables } from '@bpmn-io/extract-process-variables/zeebe';
import { BaseVariableResolver } from '../base/VariableResolver';
import { parseVariables } from './util/feelUtility';
import {
parseVariables,
getElementNamesToRemove
} from './util/feelUtility';
import {
getBusinessObject,
is
Expand Down Expand Up @@ -36,42 +39,7 @@ export default class ZeebeVariableResolver extends BaseVariableResolver {
return variables;
}

const namesToFilter = [];

// Input: remove all inputs defined after the current input definition
if (is(moddleElement, 'zeebe:Input')) {
const allInputs = inputOutput.inputParameters;

const inputsToFilter =
allInputs
.slice(allInputs.indexOf(moddleElement))
.map(o => o.target);

namesToFilter.push(...inputsToFilter);
}

const allOutputs = inputOutput.outputParameters;

// Output: remove all outputs defined after the current output definition
if (is(moddleElement, 'zeebe:Output')) {

// Get all output mappings defined after the current element, including own name
const outputsToFilter = allOutputs
.slice(allOutputs.indexOf(moddleElement))
.map(o => o.target);

namesToFilter.push(...outputsToFilter);
}

// Input or general property: remove all outputs
else if (allOutputs) {

// Input or execution-related element, remove all outputs
const outputsToFilter = allOutputs
.map(o => o.target);

namesToFilter.push(...outputsToFilter);
}
const namesToFilter = getElementNamesToRemove(moddleElement, inputOutput);

return variables.filter(v => {

Expand Down
47 changes: 46 additions & 1 deletion lib/zeebe/util/feelUtility.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { EntriesContext } from './VariableContext';
import { getExtensionElementsList } from '../../base/util/ExtensionElementsUtil';
import { getParents } from '../../base/util/scopeUtil';
import { is } from 'bpmn-js/lib/util/ModelUtil';

export function parseVariables(variables) {

Expand Down Expand Up @@ -158,7 +159,7 @@ export function getResultContext(expression, variables = {}) {
* @returns {{ expression: String, unresolved: Array<String> }}}
*/
function getExpressionDetails(variable, origin) {
const expression = getIoExpression(variable, origin) || getScriptExpression(variable, origin);
const expression = getScriptExpression(variable, origin) || getIoExpression(variable, origin);

if (!expression) {
return;
Expand Down Expand Up @@ -374,4 +375,48 @@ function filterForScope(context, variable) {
}

return scopedResults;
}

/**
* Remove input/output element name after current definition
*/
export function getElementNamesToRemove(moddleElement, inputOutput) {
const namesToFilter = [];

// Input: remove all inputs defined after the current input definition
if (is(moddleElement, 'zeebe:Input')) {
const allInputs = inputOutput.inputParameters;

const inputsToFilter =
allInputs
.slice(allInputs.indexOf(moddleElement))
.map(o => o.target);

namesToFilter.push(...inputsToFilter);
}

const allOutputs = inputOutput.outputParameters;

// Output: remove all outputs defined after the current output definition
if (is(moddleElement, 'zeebe:Output')) {

// Get all output mappings defined after the current element, including own name
const outputsToFilter = allOutputs
.slice(allOutputs.indexOf(moddleElement))
.map(o => o.target);

namesToFilter.push(...outputsToFilter);
}

// Input or general property: remove all outputs
else if (allOutputs) {

// Input or execution-related element, remove all outputs
const outputsToFilter = allOutputs
.map(o => o.target);

namesToFilter.push(...outputsToFilter);
}

return namesToFilter;
}

0 comments on commit 221d6ea

Please sign in to comment.