From 07b6aedbec273b08eeec771f3972e1d82b7442e3 Mon Sep 17 00:00:00 2001 From: gurkanguran Date: Sat, 24 Jun 2023 00:12:01 +0200 Subject: [PATCH] Fixed the issue with setVariable execution in javascript activity (#4158) * Fixed the issue with setVariable execution in javascript activity --- .../Services/JintJavaScriptEvaluator.cs | 4 ++-- .../Extensions/ExpressionExecutionContextExtensions.cs | 10 +++++----- src/modules/Elsa.Workflows.Core/Models/Variable.cs | 7 ++++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/modules/Elsa.JavaScript/Services/JintJavaScriptEvaluator.cs b/src/modules/Elsa.JavaScript/Services/JintJavaScriptEvaluator.cs index c4632ce00..a64850ac3 100644 --- a/src/modules/Elsa.JavaScript/Services/JintJavaScriptEvaluator.cs +++ b/src/modules/Elsa.JavaScript/Services/JintJavaScriptEvaluator.cs @@ -62,8 +62,8 @@ public class JintJavaScriptEvaluator : IJavaScriptEvaluator engine.SetValue("getWorkflowInstanceId", (Func)(() => context.GetActivityExecutionContext().WorkflowExecutionContext.Id)); engine.SetValue("setCorrelationId", (Action)(value => context.GetActivityExecutionContext().WorkflowExecutionContext.CorrelationId = value)); engine.SetValue("getCorrelationId", (Func)(() => context.GetActivityExecutionContext().WorkflowExecutionContext.CorrelationId)); - engine.SetValue("setVariable", (Action)((id, value) => context.SetVariable(id, value))); - engine.SetValue("getVariable", (Func)(id => context.GetVariable(id))); + engine.SetValue("setVariable", (Action)((name, value) => SetVariableInScope(context, name, value))); + engine.SetValue("getVariable", (Func)(name => GetVariableInScope(context, name))); engine.SetValue("getInput", (Func)(name => context.GetWorkflowExecutionContext().Input.GetValue(name))); engine.SetValue("getOutputFrom", (Func)((activityIdOrNodeId, outputName) => GetOutput(context, activityIdOrNodeId, outputName))); engine.SetValue("getLastResult", (Func)(() => GetLastResult(context))); diff --git a/src/modules/Elsa.Workflows.Core/Extensions/ExpressionExecutionContextExtensions.cs b/src/modules/Elsa.Workflows.Core/Extensions/ExpressionExecutionContextExtensions.cs index e01f3aa24..c315a022d 100644 --- a/src/modules/Elsa.Workflows.Core/Extensions/ExpressionExecutionContextExtensions.cs +++ b/src/modules/Elsa.Workflows.Core/Extensions/ExpressionExecutionContextExtensions.cs @@ -41,13 +41,13 @@ public static class ExpressionExecutionContextExtensions public static T? Get(this ExpressionExecutionContext context, Input? input) => input != null ? context.GetBlock(input.MemoryBlockReference).Value.ConvertTo() : default; public static T? Get(this ExpressionExecutionContext context, Output output) => context.GetBlock(output.MemoryBlockReference).Value.ConvertTo(); public static object? Get(this ExpressionExecutionContext context, Output output) => context.GetBlock(output.MemoryBlockReference).Value; - public static T? GetVariable(this ExpressionExecutionContext context, string id) => (T?)context.GetVariable(id); - public static object? GetVariable(this ExpressionExecutionContext context, string id) => new Variable(id).Get(context); - public static Variable SetVariable(this ExpressionExecutionContext context, string id, T? value, Type? storageDriverType = default) => context.SetVariable(id, (object?)value, storageDriverType, default); + public static T? GetVariable(this ExpressionExecutionContext context, string name) => (T?)context.GetVariable(name); + public static object? GetVariable(this ExpressionExecutionContext context, string name) => new Variable(name).Get(context); + public static Variable SetVariable(this ExpressionExecutionContext context, string name, T? value, Type? storageDriverType = default) => context.SetVariable(name, (object?)value, storageDriverType, default); - public static Variable SetVariable(this ExpressionExecutionContext context, string id, object? value, Type? storageDriverType, Action? configure = default) + public static Variable SetVariable(this ExpressionExecutionContext context, string name, object? value, Type? storageDriverType, Action? configure = default) { - var variable = new Variable(id, value) + var variable = new Variable(name, value) { StorageDriverType = storageDriverType }; diff --git a/src/modules/Elsa.Workflows.Core/Models/Variable.cs b/src/modules/Elsa.Workflows.Core/Models/Variable.cs index 21fb86ee9..7212d3236 100644 --- a/src/modules/Elsa.Workflows.Core/Models/Variable.cs +++ b/src/modules/Elsa.Workflows.Core/Models/Variable.cs @@ -11,13 +11,14 @@ public class Variable : MemoryBlockReference Id = Guid.NewGuid().ToString("N"); } - public Variable(string id) + public Variable(string name) : this() { - Id = id; + Name = name; } - public Variable(string id, object? value = default) : this(id) + public Variable(string name, object? value = default) : this() { + Name = name; Value = value; }