If I try to set variable that hasn't been declared in the
ruleflow header - the variables section. I get following error:
"Could not find variable someVariableName
Continuing without setting value"
Actually, the problem here is not that you cannot set the value of a variable that is not
defined in the process. It is possible to simply set the value of a variable on a
variable context instance, even if the variable has not been defined. The problem here
however is that variable contexts can be nested: a composite node can define a
sub-context, where the variables defined in this context are only accessible from inside
that composite node. Whenever you try to set the value of a variable, I must first search
for the right variable scope. This searching is based on the definition of these
variables. At this point, if it cannot find the variable, it simply does not set the
value. There are however other option:
- set the value on the top-level context (i.e. process-level variables)
- set the value on the lowest-level context (the most deeply nested container)
- allow the user to specify the context
I think I might change the default behaviour to setting the value on the process-level
scope, as that is how I already do it when getting the value of a variable.
You can also manually select the scope yourself in your action, e.g. setting to the
process-level scope can be done using:
((VariableScopeInstance)
(context.getProcessInstance().getContextInstance(VariableScope.VARIABLE_SCOPE))).setVariable("name",
value);
Of course, a Util class could hide these internal structures for you.
Kris