diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/ObjectModel/ForeachExecutor.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/ObjectModel/ForeachExecutor.cs index e6ab5e49a9..e88cd25ef6 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/ObjectModel/ForeachExecutor.cs +++ b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/ObjectModel/ForeachExecutor.cs @@ -49,7 +49,7 @@ public ForeachExecutor(Foreach model, WorkflowFormulaState state) EvaluationResult expressionResult = this.Evaluator.GetValue(this.Model.Items); if (expressionResult.Value is TableDataValue tableValue) { - this._values = [.. tableValue.Values.Select(value => value.Properties.Values.First().ToFormula())]; + this._values = [.. tableValue.Values.Select(value => value.ToFormula())]; } else { diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/ObjectModel/ForeachExecutorTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/ObjectModel/ForeachExecutorTest.cs index 63d6e15bb8..1eaf8a00e0 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/ObjectModel/ForeachExecutorTest.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/ObjectModel/ForeachExecutorTest.cs @@ -142,6 +142,34 @@ await this.TakeNextTestAsync( indexName: "CurrentIndex"); } + [Fact] + public async Task ForeachTakeNextWithMultiFieldRecordAsync() + { + // Arrange + const string CurrentValueName = "CurrentValue"; + this.SetVariableState(CurrentValueName); + + TableDataValue tableValue = DataValue.TableFromRecords( + DataValue.RecordFromFields( + new KeyValuePair("name", new StringDataValue("Alice")), + new KeyValuePair("role", new StringDataValue("Engineer")))); + + Foreach model = this.CreateModel( + displayName: nameof(ForeachTakeNextWithMultiFieldRecordAsync), + items: ValueExpression.Literal(tableValue), + valueName: CurrentValueName, + indexName: null); + ForeachExecutor action = new(model, this.State); + + // Act + await this.ExecuteAsync(action, ForeachExecutor.Steps.Next(action.Id), action.TakeNextAsync); + + // Assert + RecordValue currentValue = Assert.IsType(this.State.Get(CurrentValueName), exactMatch: false); + Assert.Equal("Alice", currentValue.GetField("name").ToObject()); + Assert.Equal("Engineer", currentValue.GetField("role").ToObject()); + } + [Fact] public async Task ForeachTakeLastAsync() {