Dmn literal expression with a dynamic variable name

Hi,

Within my dmn table I like to get access to a variable but the variable name is dynamically determined based on a counter. So I have variables that named like:
article_0
article_1
article_2

Now I have loop in my BPMN and an activity that calls the DMN business rule that needs access to the article_[counter] variable. I want to use a literal expression to handle this part and simply use in my DMN table the input variable articleValue

I can’t seem to find how I can use a dynamically determined variable name in DMN.

I know I can define an input variable in my bpmn activity and then do something like → execution.getVariable(“item_” + execution.getVariable(“counter”)) but then I am moving this logic to my bpmn activity while I think the literal expression would be better to use. I found on a forum a reference to variableContext.resolve but when I use it in DMN literal expression it says that there is no variableContext variable.

So how do I get access to the context variable within a DMN literal expression?

Hope my question makes sense :slight_smile:

1 Like

hmmm… I just changed the expression language from feel to groovy and now it seems to have access to the variable variableContext… but when I use the language feel it says: no variable found for name ‘variableContext’

in feel I need to do it differently?

Hi @j0hnli,

this is an interesting question.

In FEEL, there is a built-in function get value() that accepts a dynamic name. But the function would work only if the variable is embedded in a context (i.e. a JSON document/ Java map structure).

In our case, you would need to embed the article_* variable into a map or other object in the BPMN process.

I created a new feature request: Access variables with dynamic names · Issue #291 · camunda/feel-scala · GitHub

Does this help you?

Best regards,
Philipp