Skip to content

Commit

Permalink
Merge pull request #6358 from elsa-workflows/bug/6347
Browse files Browse the repository at this point in the history
Fix activity output
  • Loading branch information
sfmskywalker authored Jan 30, 2025
2 parents 1df28f1 + 71c0a53 commit 2bac946
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public IEnumerable<ActivityOutputRecord> FindMany(string activityId, string? out
var key = CreateActivityIdLookupKey(activityId, outputName);
return !_recordsByActivityIdAndOutputName.TryGetValue(key, out var records)
? null
: records.FirstOrDefault()?.Value;
: records.LastOrDefault()?.Value; // Always return the last value.
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Elsa.Extensions;
using Elsa.Workflows.Activities;

namespace Elsa.Workflows.IntegrationTests.Scenarios.ActivityOutputs;

public class LoopingWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder builder)
{
var readCurrentValue = new Inline<string>(context => context.GetVariable<string>("CurrentValue")!);

builder.Root = new ForEach<string>(
[
"Item 1",
"Item 2",
"Item 3"
])
{
Body = new Sequence
{
Activities =
[
readCurrentValue,
new WriteLine(context =>
{
var currentValue = context.GetVariable<string>("CurrentValue");
var activityResult = context.GetActivityExecutionContext().GetResult(readCurrentValue);
return $"Current value: {currentValue}, Activity result: {activityResult}";
})
]
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,21 @@ public async Task Test1()
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[]
{
"The result of 4 and 6 is 10.",
"The last result is 10."
"The result of 4 and 6 is 10.", "The last result is 10."
}, lines);
}

[Fact(DisplayName = "The last activity output is returned.")]
public async Task Test2()
{
await _services.PopulateRegistriesAsync();
await _workflowRunner.RunAsync<LoopingWorkflow>();
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[]
{
"Current value: Item 1, Activity result: Item 1",
"Current value: Item 2, Activity result: Item 2",
"Current value: Item 3, Activity result: Item 3"
}, lines);
}
}

0 comments on commit 2bac946

Please sign in to comment.