diff --git a/src/modules/Elsa.JavaScript/Services/JintJavaScriptEvaluator.cs b/src/modules/Elsa.JavaScript/Services/JintJavaScriptEvaluator.cs index 0e2ad18e3..be6d1334f 100644 --- a/src/modules/Elsa.JavaScript/Services/JintJavaScriptEvaluator.cs +++ b/src/modules/Elsa.JavaScript/Services/JintJavaScriptEvaluator.cs @@ -67,7 +67,7 @@ public class JintJavaScriptEvaluator : IJavaScriptEvaluator engine.SetValue("getCorrelationId", (Func)(() => context.GetActivityExecutionContext().WorkflowExecutionContext.CorrelationId)); 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("getInput", (Func)(name => GetInput(context, name))); engine.SetValue("getOutputFrom", (Func)((activityIdName, outputName) => GetOutput(context, activityIdName, outputName))); engine.SetValue("getLastResult", (Func)(() => GetLastResult(context))); @@ -128,6 +128,20 @@ public class JintJavaScriptEvaluator : IJavaScriptEvaluator return workflowExecutionContext.GetLastActivityResult(); } + private object? GetInput(ExpressionExecutionContext expressionExecutionContext, string name) + { + // If there's a variable in the current scope with the specified name, return that. + var variable = expressionExecutionContext.GetVariable(name); + + if (variable != null) + return variable.Get(expressionExecutionContext); + + // Otherwise, return the input. + var workflowExecutionContext = expressionExecutionContext.GetWorkflowExecutionContext(); + var input = workflowExecutionContext.Input; + return input.TryGetValue(name, out var value) ? value : default; + } + private static object? GetOutput(ExpressionExecutionContext context, string activityIdOrName, string? outputName) { var workflowExecutionContext = context.GetWorkflowExecutionContext();