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 4bf154bf9e..dd247936f1 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 @@ -105,7 +105,7 @@ export class IteratorWorkflowAction implements WorkflowActionInterface { hasProcessedAllItems, }; - if (!hasProcessedAllItems) { + if (!hasProcessedAllItems && currentItemIndex > 0) { await this.resetStepsInLoop({ iteratorStepId, initialLoopStepIds, @@ -140,6 +140,14 @@ export class IteratorWorkflowAction implements WorkflowActionInterface { steps, }); + const workflowRunToUpdate = + await this.workflowRunWorkspaceService.getWorkflowRunOrFail({ + workflowRunId, + workspaceId, + }); + + const stepInfos = workflowRunToUpdate.state.stepInfos; + await this.workflowRunWorkspaceService.updateWorkflowRunStepInfos({ stepInfos: stepIdsToReset.reduce( (acc, stepId) => { @@ -147,6 +155,14 @@ export class IteratorWorkflowAction implements WorkflowActionInterface { 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; diff --git a/packages/twenty-shared/src/workflow/types/WorkflowRunStateStepInfos.ts b/packages/twenty-shared/src/workflow/types/WorkflowRunStateStepInfos.ts index fcb1d6ea98..c1e9642b95 100644 --- a/packages/twenty-shared/src/workflow/types/WorkflowRunStateStepInfos.ts +++ b/packages/twenty-shared/src/workflow/types/WorkflowRunStateStepInfos.ts @@ -11,6 +11,11 @@ export type WorkflowRunStepInfo = { result?: object; error?: string; status: StepStatus; + history?: { + status: StepStatus; + result?: object; + error?: string; + }[]; }; export type WorkflowRunStepInfos = Record;