snapshot of https://github.com/twentyhq/twenty.git (main, 2026-09-17; blobs > 131072B omitted)
Some checks failed
App Prod-Parity E2E Dispatch / dispatch (push) Failing after 10s
CD Storybook UI / build (push) Failing after 3m25s
CD Storybook UI / dispatch (push) Has been skipped
CD deploy main / website-changed-files (push) Successful in 18m8s
CI Agent Skills / changed-files-check (push) Successful in 18m9s
CI Create App E2E minimal / changed-files-check (push) Successful in 24s
CI Create App / changed-files-check (push) Successful in 26s
CI Docs / changed-files-check (push) Successful in 26s
CI Emails / changed-files-check (push) Successful in 28s
CI Example App Hello World / changed-files-check (push) Successful in 23s
CI Front / changed-files-check (push) Has been skipped
CI Example App Postcard / changed-files-check (push) Successful in 27s
CI UI / changed-files-check (push) Has been skipped
CI Utils Test / changed-files-check (push) Successful in 45s
CI Twenty Apps / discover (push) Successful in 1m3s
CD deploy main / deploy-main (push) Failing after 3s
CI Agent Skills / agent-skills-validate (push) Has been skipped
CI Create App / create-app-test (lint) (push) Has been skipped
CI Emails / emails-test (push) Has been skipped
CI Front / front-task (lingui:compile) (push) Has been skipped
CI Front / front-task (lint) (push) Has been skipped
CI Example App Postcard / example-app-postcard (push) Has been skipped
CI UI / ui-task (lint) (push) Has been skipped
CI UI / ui-task (pack-size) (push) Has been skipped
CI UI / ui-task (size) (push) Has been skipped
CI UI / ui-task (test) (push) Has been skipped
CI UI / ui-task (typecheck) (push) Has been skipped
CI Utils Test / utils-test (push) Has been skipped
CI Twenty Apps / ${{ matrix.app.name }} (push) Has been skipped
CI Emails / ci-emails-status-check (push) Successful in 2s
CI Example App Hello World / ci-example-app-hello-world-status-check (push) Successful in 2s
CI Example App Postcard / ci-example-app-postcard-status-check (push) Successful in 3s
CI UI / ui-sb-test (push) Has been skipped
CI Utils Test / ci-utils-test-status-check (push) Successful in 2s
CI Twenty Apps / ci-twenty-apps-status-check (push) Successful in 2s
CI UI / ci-ui-status-check (push) Successful in 2s
CI Desktop / desktop (push) Failing after 1m8s
Push docs to Crowdin / Push documentation to Crowdin (push) Failing after 55s
Push translations to Crowdin / Extract and upload translations (push) Failing after 5s
Push website translations to Crowdin / Extract and upload website translations (push) Failing after 5s
CI Create App / create-app-test (test) (push) Has been skipped
CI Create App / create-app-test (typecheck) (push) Has been skipped
CI Docs / docs-lint (push) Has been skipped
CI Example App Hello World / example-app-hello-world (push) Has been skipped
CI Front / front-task (lingui:extract) (push) Has been skipped
CI Front / front-task (test) (push) Has been skipped
CI Front / front-task (typecheck) (push) Has been skipped
CI UI / ui-sb-build (push) Failing after 1m32s
CI Twenty Apps / ${{ matrix.app.name }} (${{ matrix.server-source }}) (push) Has been skipped
CI Agent Skills / agent-skills-publish (push) Has been skipped
CI Create App / ci-create-app-status-check (push) Successful in 2s
CI Agent Skills / agent-skills-remote-source (push) Has been skipped
CI Create App E2E minimal / create-app-e2e-minimal (push) Has been cancelled
CI E2E Main / e2e-test (push) Has been cancelled
CI Front / front-sb-build (push) Has been cancelled
CI Front / front-build (push) Has been cancelled
CI Create App E2E minimal / ci-create-app-e2e-minimal-status-check (push) Has been cancelled
CI E2E Main / ci-e2e-main-status-check (push) Has been cancelled
CI E2E Main / notify-main-ci-failure (push) Has been cancelled
CI E2E Main / qa-scout-comment (push) Has been cancelled
CI Front / front-sb-test (push) Has been cancelled
CI Front / front-sb-screenshots (push) Has been cancelled
CI Front / ci-front-status-check (push) Has been cancelled
DPA Sub-Processor Sync / sync-subprocessors (push) Failing after 3s
AI Catalog Sync / sync-catalog (push) Failing after 3s

This commit is contained in:
upstream-mirror
2026-09-17 23:28:13 +05:00
commit e7da97194a
32688 changed files with 4208681 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
---
title: Code 액션에서 배열 처리
description: 워크플로의 Code 액션에서 배열 입력을 올바르게 처리하는 방법을 알아보세요.
---
Code 액션에서 배열을 다룰 때 흔히 마주하는 두 가지 문제가 있습니다:
1. **문자열로 전달된 배열** — 외부 시스템이나 이전 단계에서 실제 배열이 아닌 문자열로 전달됨
2. **개별 항목을 선택할 수 없음** — 배열 전체만 선택할 수 있고, 그 안의 특정 필드는 선택할 수 없음
둘 다 Code 노드로 해결할 수 있습니다.
## 문자열에서 배열 파싱하기
배열은 워크플로 단계 간에 네이티브 배열이 아니라 문자열이나 JSON으로 전달되는 경우가 자주 있습니다. 다음과 같은 경우에 발생합니다:
* HTTP Request로 외부 API에서 데이터를 받을 때
* 웹훅 페이로드를 처리할 때
* 워크플로 단계 간에 데이터를 전달할 때
**해결책**: Code 액션의 시작 부분에 다음 패턴을 추가하세요:
```javascript
export const main = async (params: {
users: any;
}): Promise<object> => {
const { users } = params;
// Handle input that may come as a string or an array
const usersFormatted = typeof users === "string" ? JSON.parse(users) : users;
// Now you can safely work with usersFormatted as an array
return {
users: usersFormatted.map((user) => ({
...user,
activityStatus: String(user.activityStatus).toUpperCase(),
})),
};
};
```
핵심 구문 `typeof users === "string" ? `JSON.parse(users) : users\` 는 입력이 문자열인지 확인하고, 필요하면 파싱하며, 이미 배열인 경우 그대로 사용합니다.
## 배열에서 개별 필드 추출하기
웹훅이 `answers: [...]`와 같은 배열을 반환할 수 있지만, 이후 워크플로 단계에서는 **배열 전체**만 선택할 수 있고 그 안의 개별 항목은 선택할 수 없습니다.
**해결책**: 특정 필드를 추출하여 구조화된 객체로 반환하도록 Code 노드를 추가하세요:
```javascript
export const main = async (params: {
answers: any;
}): Promise<object> => {
const { answers } = params;
// Handle input that may come as a string or an array
const answersFormatted = typeof answers === "string"
? JSON.parse(answers)
: answers;
// Extract specific fields from the array
const firstname = answersFormatted[0]?.text || "";
const name = answersFormatted[1]?.text || "";
return {
answer: {
firstname,
name
}
};
};
```
Code 노드는 배열 대신 구조화된 객체를 반환합니다. 이후 단계에서는 변수 선택기에서 `answer.firstname` 및 `answer.name`과 같은 개별 필드를 선택할 수 있습니다.
<Tip>
**배열에서 필드를 추출하는 대신 배열을 순회(loop)하고 싶으신가요?** Code 또는 Logic Function 단계가 최상위 배열을 반환하는 경우, 해당 결과를 바로 [Iterator](/l/ko/user-guide/workflows/capabilities/use-iterator)에 전달할 수 있습니다. 해당 단계의 **Whole list** 옵션을 Iterator의 입력으로 선택한 다음, 루프 안에서 각 요소를 `{{iterator.currentItem}}`으로 참조하면 됩니다. 그 경우에는 배열을 객체로 변환할 필요가 없습니다.
</Tip>
<Tip>
코드 편집기 오른쪽 상단의 사각형 아이콘을 클릭하여 전체 화면으로 표시하세요 — 기본 편집기 너비가 제한되어 있어 유용합니다.
</Tip>