[Workflows] Allow iterator to take whole item as variable (#22031)
**Select the whole item in iterator loops, and iterate over a step's array output** ## Summary Two related improvements to working with lists in workflows: - Pick the current item as a whole inside an iterator loop. Previously, in a node inside the loop, you could only reference individual fields of the Iterator's current item. Now you can select the whole item (e.g. a full record) — useful for passing it straight into a downstream step. <img width="1270" height="744" alt="Screenshot 2026-06-23 at 17 02 47" src="https://github.com/user-attachments/assets/6b92e72e-ec25-4c1a-9841-3a438210e753" /> - Iterate over a step's array output. A Code / Logic Function step that returns a top-level array couldn't be fed to the Iterator: its output was flattened into indexed entries (0, 1, …) with no way to select the array as a whole. A new "Whole list" option selects the step's entire output, and the Iterator infers the per-iteration item shape from it. <img width="1026" height="728" alt="Screenshot 2026-06-23 at 17 17 53" src="https://github.com/user-attachments/assets/db07dcd8-4fb8-4db9-8b45-aa56051d9f3b" /> Together these complete the loop ergonomics: select a list → iterate → reference the current item (whole or by field) downstream — matching the model used by tools like Windmill. ## What changed - The variable picker offers a "Use the whole item" option when viewing an iterator's current item, and a "Whole list" option when a step returns a top-level array. - The Iterator's current-item schema can now be inferred from a variable pointing at a step's whole output. ## Risks for existing workflows None expected. The change is purely additive: - No DB migration and no change to how output schemas are stored or read — existing schemas, variables, and iterators behave identically. - No change to runtime variable resolution; existing {{step.field}} and current-item references are untouched. - The new options only apply to new selections (whole item / whole list); all existing paths take the unchanged code path. - The only edge case: array detection is heuristic (an output whose keys are exactly 0…n-1), so an object that happens to have those keys would also show "Whole list". This is rare for real outputs, affects nothing unless a user selects it, and fails safe — the Iterator validates its input and throws a clear "items must be an array" error if a non-array is passed. <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/twentyhq/twenty/pull/22031?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. --> --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
+21
-1
@@ -11,8 +11,10 @@ import {
|
||||
buildManualTriggerMetadataNode,
|
||||
BulkRecordsAvailability,
|
||||
extractRawVariableNamePart,
|
||||
getCurrentItemSchemaFromFlattenedArrayOutputSchema,
|
||||
GlobalAvailability,
|
||||
isBaseOutputSchemaV2,
|
||||
isFlattenedArrayOutputSchema,
|
||||
navigateOutputSchemaProperty,
|
||||
SingleRecordAvailability,
|
||||
TRIGGER_STEP_ID,
|
||||
@@ -653,8 +655,26 @@ export class WorkflowSchemaWorkspaceService {
|
||||
case WorkflowActionType.HTTP_REQUEST:
|
||||
case WorkflowActionType.LOGIC_FUNCTION: {
|
||||
const propertyPath = extractPropertyPathFromVariable(items);
|
||||
const outputSchema = this.getOutputSchemaWithExpectedFallback(
|
||||
step.settings,
|
||||
);
|
||||
|
||||
const variableTargetsWholeStepOutput = propertyPath.length === 0;
|
||||
|
||||
if (variableTargetsWholeStepOutput) {
|
||||
if (!isFlattenedArrayOutputSchema(outputSchema)) {
|
||||
return DEFAULT_ITERATOR_CURRENT_ITEM;
|
||||
}
|
||||
|
||||
return (
|
||||
getCurrentItemSchemaFromFlattenedArrayOutputSchema({
|
||||
schema: outputSchema,
|
||||
}) ?? DEFAULT_ITERATOR_CURRENT_ITEM
|
||||
);
|
||||
}
|
||||
|
||||
const schemaNode = navigateOutputSchemaProperty({
|
||||
schema: this.getOutputSchemaWithExpectedFallback(step.settings),
|
||||
schema: outputSchema,
|
||||
propertyPath,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user