Skip to content

The open alternative to Salesforce, designed for AI.

Store history when iterator reset the step info (#14684)

Thomas Trompette3b1657b6faa7
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 4bf154bf9e5..dd247936f1d 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 fcb1d6ea985..c1e9642b95b 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<string, WorkflowRunStepInfo>;