Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setVariable or getVariable function not working #4789

Closed
nilesh-darji opened this issue Jan 11, 2024 · 2 comments
Closed

setVariable or getVariable function not working #4789

nilesh-darji opened this issue Jan 11, 2024 · 2 comments
Assignees
Labels
elsa 3 This issue is specific to Elsa 3 enhancement New feature or request

Comments

@nilesh-darji
Copy link

nilesh-darji commented Jan 11, 2024

Summary:

I'm encountering a problem where the setVariable or getVariable functions are not working as expected within the Run JavaScript action in Elsa 3.0.2 This issue prevents me from effectively setting and retrieving variables within my workflows.

Steps to Reproduce:

  1. Create a workflow in Elsa 3.0 that includes a Run JavaScript activity.
  2. Within the JavaScript code, attempt to use setVariable to assign a value to a variable.
  3. Subsequently, try to retrieve the value using getVariable.

Please find workflow json
get_variable.json

@nilesh-darji nilesh-darji changed the title setVariable or getVariable functions are not working setVariable or getVariable function not working Jan 11, 2024
@sfmskywalker sfmskywalker self-assigned this Jan 15, 2024
@sfmskywalker
Copy link
Member

The issue stems from the fact that the setVariable method attempts to find an existing scope for the specified variable name. When you define a workflow variable with this name, it will work.

image

Without defining the variable first, it will fail.
Although that's why it doesn't work without first defining the variable, I think we should support defining variables on the fly as per your workflow.

For now, I attached an updated workflow JSON file that works for your scenario.

I will think about a way to allow for the dynamic creation of workflow variables.

@sfmskywalker sfmskywalker added enhancement New feature or request elsa 3 This issue is specific to Elsa 3 labels Jan 15, 2024
sfmskywalker added a commit that referenced this issue Jan 15, 2024
The update introduced checks if a variable exists before attempting to set its value in the ExpressionExecutionContextExtensions. If the variable doesn't exist, it now creates one automatically.

Fixes #4789
sfmskywalker added a commit that referenced this issue Jan 15, 2024
* Disable MassTransitRabbitMq in Elsa.Server.Web.

* Create variable if not exists in Workflow.Core

The update introduced checks if a variable exists before attempting to set its value in the ExpressionExecutionContextExtensions. If the variable doesn't exist, it now creates one automatically.

Fixes #4789

* Remove unnecessary comment

The comment indicating to create a variable if it doesn't exist was deemed superfluous and removed from the ExpressionExecutionContextExtensions.cs file. This improves code cleanliness as the functionality is self-explanatory through the existing code structure.
@sfmskywalker
Copy link
Member

Done via #4800

lahma pushed a commit to lahma/elsa-core that referenced this issue Feb 2, 2024
…lows#4800)

* Disable MassTransitRabbitMq in Elsa.Server.Web.

* Create variable if not exists in Workflow.Core

The update introduced checks if a variable exists before attempting to set its value in the ExpressionExecutionContextExtensions. If the variable doesn't exist, it now creates one automatically.

Fixes elsa-workflows#4789

* Remove unnecessary comment

The comment indicating to create a variable if it doesn't exist was deemed superfluous and removed from the ExpressionExecutionContextExtensions.cs file. This improves code cleanliness as the functionality is self-explanatory through the existing code structure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
elsa 3 This issue is specific to Elsa 3 enhancement New feature or request
Projects
Status: Done
Development

No branches or pull requests

2 participants