Skip to content

Commit

Permalink
Improve variable resolution in workflow activity
Browse files Browse the repository at this point in the history
Added a reference to Variable.Id in the SetVariable activity within the Elsa.Workflows.Core module to ensure the correct variable scope is utilized. This change enhances the precision of the variable resolution process by ensuring the correct variable is identified and updated.
  • Loading branch information
sfmskywalker committed Dec 29, 2023
1 parent cb4dfea commit 17452f7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/modules/Elsa.Workflows.Core/Activities/SetVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Elsa.Workflows.Attributes;
using Elsa.Workflows.Memory;
using Elsa.Workflows.Models;
using Elsa.Workflows.UIHints;
using JetBrains.Annotations;

namespace Elsa.Workflows.Activities;
Expand Down Expand Up @@ -100,7 +101,10 @@ public SetVariable([CallerFilePath] string? source = default, [CallerLineNumber]
/// <inheritdoc />
protected override void Execute(ActivityExecutionContext context)
{
// Always refer to the variable by ID to ensure that the variable is resolved from the correct scope.
var variableId = Variable.Id;
var variable = context.ExpressionExecutionContext.EnumerateVariablesInScope().FirstOrDefault(x => x.Id == variableId);
var value = context.Get(Value);
context.SetVariable(Variable.Name, value);
variable?.Set(context, value);
}
}

0 comments on commit 17452f7

Please sign in to comment.