elsa-workflows / elsa-workflows/elsa-core
[BUG] variables are not available in the JS expression engine context. Only accessors are available.
- Dominant language
- C#
- Stars
- 7.9k
- Forks
- 1.5k
- Avg merge
- 15h 22m
- Merged PRs (30d)
- 114
Description
We are not able to use variable names directly in the expressions.
I am setting variables to the context using context.SetVariable() extension. But these variables are not pushed to the JINT context while evaluating expressions. Only the accessors (get()) are available in expression context.
How we are supposed to use the variables in expression ? are we suggesting users to use get in their expressions? In elsa 2 this was straightforward.
## Steps to Reproduce
As I can see, even if I set the variable in a context and immediately try to use that in an expression, its not working..
Steps:
In any activity ExceuteAsync,
```
context.SetVariable("url", "https://www.abc.com");
var expression = "url";
var exp = new Expression("JavaScript", expression);
var result = await engine!.EvaluateAsync(exp,context.ExpressionExecutionContext);
```
This will throw an error saying 'url' is not defined. But at the same time, if I use 'getUrl()' the evaluation works fine.
_______
I checked the code base Elsa 2 & 3 -In v3, during the js engine configuration , we are not pushing the variables to the Jint context. In Elsa 2 we are translating variables and then pushing them to the Jint context.
In Elsa 2, ConfigureJavaScriptEngine.cs ,

This is missing in Elsa 3 (as per my understanding) and no alternatives provided. Not sure this is intentional.
## Expected Behavior
1. variables in the context should be available in the js engine for evaluating expressions.
## Actual Behavior
Expressions with direct variable references are failing.
## Environment
- **Elsa 3.1.3
Contributor guide
Assessment
This issue has not been assessed yet.