diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/iterator/iterator.workflow-action.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/iterator/iterator.workflow-action.ts index dd247936f1d..f8c5a8340f4 100644 --- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/iterator/iterator.workflow-action.ts +++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/iterator/iterator.workflow-action.ts @@ -147,28 +147,48 @@ export class IteratorWorkflowAction implements WorkflowActionInterface { }); const stepInfos = workflowRunToUpdate.state.stepInfos; + const subStepsInfos = stepIdsToReset.reduce( + (acc, stepId) => { + acc[stepId] = { + status: StepStatus.NOT_STARTED, + result: undefined, + error: undefined, + history: [ + ...(stepInfos[stepId]?.history ?? []), + { + result: stepInfos[stepId]?.result, + error: stepInfos[stepId]?.error, + status: stepInfos[stepId]?.status, + }, + ], + }; + + return acc; + }, + {} as Record, + ); + + const iteratorStepInfo = stepInfos[iteratorStepId]; + + const stepInfosToUpdate = { + ...subStepsInfos, + [iteratorStepId]: { + ...iteratorStepInfo, + result: undefined, + error: undefined, + history: [ + ...(iteratorStepInfo?.history ?? []), + { + result: iteratorStepInfo?.result, + error: iteratorStepInfo?.error, + status: iteratorStepInfo?.status, + }, + ], + }, + }; await this.workflowRunWorkspaceService.updateWorkflowRunStepInfos({ - stepInfos: stepIdsToReset.reduce( - (acc, stepId) => { - acc[stepId] = { - status: StepStatus.NOT_STARTED, - result: undefined, - error: undefined, - history: [ - ...(stepInfos[stepId]?.history ?? []), - { - result: stepInfos[stepId]?.result, - error: stepInfos[stepId]?.error, - status: stepInfos[stepId]?.status, - }, - ], - }; - - return acc; - }, - {} as Record, - ), + stepInfos: stepInfosToUpdate, workflowRunId, workspaceId, });