diff --git a/lib/base/VariableResolver.js b/lib/base/VariableResolver.js index 83a9dd1..a383543 100644 --- a/lib/base/VariableResolver.js +++ b/lib/base/VariableResolver.js @@ -1,6 +1,7 @@ import { getBusinessObject, is } from 'bpmn-js/lib/util/ModelUtil'; import CachedValue from './util/CachedValue'; import { getParents, getScope } from './util/scopeUtil'; +import { uniqueBy } from 'min-dash'; /** * @typedef {Object} AdditionalVariable @@ -257,15 +258,18 @@ export class BaseVariableResolver { const root = getRootElement(bo); const allVariables = await this.getProcessVariables(root); + // keep only unique variables based on name property + const uniqueVariables = uniqueBy('name',allVariables.reverse()); + // (1) get variables for given scope - var scopeVariables = allVariables.filter(function(variable) { + var scopeVariables = uniqueVariables.filter(function(variable) { return variable.scope.id === bo.id; }); // (2) get variables for parent scopes var parents = getParents(bo); - var parentsScopeVariables = allVariables.filter(function(variable) { + var parentsScopeVariables = uniqueVariables.filter(function(variable) { return parents.find(function(parent) { return parent.id === variable.scope.id; }); diff --git a/lib/zeebe/VariableResolver.js b/lib/zeebe/VariableResolver.js index 5a032a6..d3f5054 100644 --- a/lib/zeebe/VariableResolver.js +++ b/lib/zeebe/VariableResolver.js @@ -10,7 +10,6 @@ import { } from 'bpmn-js/lib/util/ModelUtil'; import { getInputOutput } from '../base/util/ExtensionElementsUtil'; - const HIGH_PRIORITY = 2000; /** @@ -40,8 +39,7 @@ export default class ZeebeVariableResolver extends BaseVariableResolver { } const namesToFilter = getElementNamesToRemove(moddleElement, inputOutput); - - return variables.filter(v => { + return variables.filter(v=> { // Keep all variables that are also defined in other elements if (v.origin.length > 1 || v.origin[0] !== bo) { diff --git a/lib/zeebe/util/feelUtility.js b/lib/zeebe/util/feelUtility.js index e71461c..0a90713 100644 --- a/lib/zeebe/util/feelUtility.js +++ b/lib/zeebe/util/feelUtility.js @@ -159,7 +159,12 @@ export function getResultContext(expression, variables = {}) { * @returns {{ expression: String, unresolved: Array }}} */ function getExpressionDetails(variable, origin) { - const expression = getScriptExpression(variable, origin) || getIoExpression(variable, origin); + + // if variable scope is parent scope, first check IoExpression and then ScriptExpression + // if variable is local scope (origin), first check ScriptExpression and then IoExpression + const expression = variable.scope !== origin + ? getIoExpression(variable, origin) || getScriptExpression(variable, origin) + : getScriptExpression(variable, origin) || getIoExpression(variable, origin); if (!expression) { return;