elsa-workflows / elsa-workflows/elsa-core
[BUG] Bulk dispatch workflows with input repeats the last item
- Dominant language
- C#
- Stars
- 7.9k
- Forks
- 1.5k
- Avg merge
- 15h 22m
- Merged PRs (30d)
- 114
Description
**Description:**
Bulk dispatch workflows without input works great. However, bulk dispatch workflows with input repeats the last item. The expected behavior is that each workflow should receive its respective input item.
**Steps to Reproduce:**
1. Use the provided `EmployeeGreetingWorkflow` and `GreetEmployeesWorkflow` classes.
2. Observe the console output when executing the `GreetEmployeesWorkflow`.
**Code for Testing:**
1. `EmployeeGreetingWorkflow.cs`
```csharp
using Elsa.Extensions;
using Elsa.Workflows.Activities;
using Elsa.Workflows.Contracts;
namespace Elsa.Workflows.ComponentTests.Scenarios.BulkDispatchWorkflows.Workflows;
public class EmployeeGreetingWorkflow : WorkflowBase
{
public static readonly string DefinitionId = Guid.NewGuid().ToString();
protected override void Build(IWorkflowBuilder builder)
{
builder.WithDefinitionId(DefinitionId);
var employeeName = builder.WithInput("Employee");
builder.Root = new Sequence
{
Activities =
{
new WriteLine(x => $"Hello {x.GetInput(employeeName)}")
}
};
}
}
```
2. `GreetEmployeesWorkflow.cs`
```csharp
using Elsa.JavaScript.Models;
using Elsa.Workflows.Activities;
using Elsa.Workflows.Contracts;
namespace Elsa.Workflows.ComponentTests.Scenarios.BulkDispatchWorkflows.Workflows;
public class GreetEmployeesWorkflow : WorkflowBase
{
public static readonly string DefinitionId = Guid.NewGuid().ToString();
protected override void Build(IWorkflowBuilder builder)
{
var employeeNames = new[]
{
"Alice", "Bob", "Charlie"
};
var inputEntries = employeeNames.Select(x => new Dictionary
{
["Employee"] = x
});
builder.WithDefinitionId(DefinitionId);
builder.Root = new Sequence
{
Activities =
{
new WriteLine("Bulk dispatching workflows without input works great."),
new Runtime.Activities.BulkDispatchWorkflows
{
WorkflowDefinitionId = new(EmployeeGreetingWorkflow.DefinitionId),
Items = new(inputEntries),
WaitForCompletion = new(true),
},
new WriteLine("But Bulk dispatching workflows with input repeats the last item."),
new Runtime.Activities.BulkDispatchWorkflows
{
WorkflowDefinitionId = new(EmployeeGreetingWorkflow.DefinitionId),
Items = new(inputEntries),
WaitForCompletion = new(true),
Input = new (JavaScriptExpression.Create("return {'Test Input':'Test'}")),
}
}
};
}
}
```
**Console Output:**
```
Bulk dispatching workflows without input works great.
Hello Bob
Hello Alice
Hello Charlie
But Bulk dispatching workflows with input repeats the last item.
Hello Charlie
Hello Charlie
Hello Charlie
```
As shown in the console output, the workflows without input work as expected, greeting Bob, Alice, and Charlie respectively. However, the workflows with input repeat the last name, greeting Charlie three times.

[GreetEmployeesWorkflow.zip](https://github.com/elsa-workflows/elsa-core/files/15421350/GreetEmployeesWorkflow.zip)
Contributor guide
Assessment
This issue has not been assessed yet.