Skip to content

The open alternative to Salesforce, designed for AI.

Pass fieldMetadataId in if/else workflow node (#28443)

BOHEUSf08ce7111b25
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/types/WorkflowFormActionField.ts b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/types/WorkflowFormActionField.ts
index 8b0084d051c..8d0531427de 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/types/WorkflowFormActionField.ts
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/types/WorkflowFormActionField.ts
@@ -1,11 +1,17 @@
import { type WorkflowFormFieldType } from '@/workflow/workflow-steps/workflow-actions/form-action/types/WorkflowFormFieldType';
+type WorkflowFormActionFieldSettings = {
+ objectName?: string;
+ selectType?: string;
+ selectedFieldId?: string;
+};
+
export type WorkflowFormActionField = {
id: string;
name: string;
label: string;
type: WorkflowFormFieldType;
placeholder?: string;
- settings?: Record<string, any>;
+ settings?: WorkflowFormActionFieldSettings;
value?: any;
};
diff --git a/packages/twenty-front/src/modules/workflow/workflow-variables/types/FormOutputSchema.ts b/packages/twenty-front/src/modules/workflow/workflow-variables/types/FormOutputSchema.ts
deleted file mode 100644
index 0e2f127350e..00000000000
--- a/packages/twenty-front/src/modules/workflow/workflow-variables/types/FormOutputSchema.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-import { type RecordOutputSchemaV2 } from '@/workflow/workflow-variables/types/RecordOutputSchemaV2';
-import { type FieldMetadataType } from 'twenty-shared/types';
-
-type FormFieldLeaf = {
- isLeaf: true;
- type: FieldMetadataType;
- label: string;
- value: any;
-};
-
-type FormFieldNode = {
- isLeaf: false;
- label: string;
- value: RecordOutputSchemaV2;
-};
-
-export type FormOutputSchema = Record<string, FormFieldLeaf | FormFieldNode>;
diff --git a/packages/twenty-front/src/modules/workflow/workflow-variables/types/StepOutputSchemaV2.ts b/packages/twenty-front/src/modules/workflow/workflow-variables/types/StepOutputSchemaV2.ts
index a9db989e3d6..c983ec54113 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-variables/types/StepOutputSchemaV2.ts
+++ b/packages/twenty-front/src/modules/workflow/workflow-variables/types/StepOutputSchemaV2.ts
@@ -4,12 +4,12 @@ import {
} from '@/workflow/types/Workflow';
import { type CodeOutputSchema } from '@/workflow/workflow-variables/types/CodeOutputSchema';
import { type FindRecordsOutputSchema } from '@/workflow/workflow-variables/types/FindRecordsOutputSchema';
-import { type FormOutputSchema } from '@/workflow/workflow-variables/types/FormOutputSchema';
import { type IteratorOutputSchema } from '@/workflow/workflow-variables/types/IteratorOutputSchema';
import { type RecordOutputSchemaV2 } from '@/workflow/workflow-variables/types/RecordOutputSchemaV2';
import { type WaitForEventOutputSchema } from '@/workflow/workflow-variables/types/WaitForEventOutputSchema';
import {
type BaseOutputSchemaV2,
+ type FormOutputSchema,
type ManualTriggerOutputSchema,
} from 'twenty-shared/workflow';
diff --git a/packages/twenty-front/src/modules/workflow/workflow-variables/utils/generate/__tests__/generateFormOutputSchema.test.ts b/packages/twenty-front/src/modules/workflow/workflow-variables/utils/generate/__tests__/generateFormOutputSchema.test.ts
index 57d0b01ee97..6ad33dc9e45 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-variables/utils/generate/__tests__/generateFormOutputSchema.test.ts
+++ b/packages/twenty-front/src/modules/workflow/workflow-variables/utils/generate/__tests__/generateFormOutputSchema.test.ts
@@ -39,6 +39,42 @@ describe('generateFormOutputSchema', () => {
});
});
+ it('should expose the selected field metadata id for SELECT field', () => {
+ const formFields: WorkflowFormActionField[] = [
+ {
+ id: 'field-1',
+ name: 'status',
+ label: 'Status',
+ type: FieldMetadataType.SELECT,
+ settings: { selectedFieldId: 'status-field-metadata-id' },
+ },
+ ];
+
+ const result = generateFormOutputSchema(formFields, []);
+
+ expect(result.status).toMatchObject({
+ isLeaf: true,
+ type: 'SELECT',
+ fieldMetadataId: 'status-field-metadata-id',
+ });
+ });
+
+ it('should not expose a field metadata id for a SELECT field with no selected field', () => {
+ const formFields: WorkflowFormActionField[] = [
+ {
+ id: 'field-1',
+ name: 'status',
+ label: 'Status',
+ type: FieldMetadataType.SELECT,
+ settings: { selectType: 'EXISTING_FIELD' },
+ },
+ ];
+
+ const result = generateFormOutputSchema(formFields, []);
+
+ expect(result.status).not.toHaveProperty('fieldMetadataId');
+ });
+
it('should use placeholder as value when defined', () => {
const formFields: WorkflowFormActionField[] = [
{
diff --git a/packages/twenty-front/src/modules/workflow/workflow-variables/utils/generate/generateFormOutputSchema.ts b/packages/twenty-front/src/modules/workflow/workflow-variables/utils/generate/generateFormOutputSchema.ts
index a4fb2c04e07..62f08530440 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-variables/utils/generate/generateFormOutputSchema.ts
+++ b/packages/twenty-front/src/modules/workflow/workflow-variables/utils/generate/generateFormOutputSchema.ts
@@ -1,10 +1,13 @@
import { type EnrichedObjectMetadataItem } from '@/object-metadata/types/EnrichedObjectMetadataItem';
import { type WorkflowFormActionField } from '@/workflow/workflow-steps/workflow-actions/form-action/types/WorkflowFormActionField';
-import { type FormOutputSchema } from '@/workflow/workflow-variables/types/FormOutputSchema';
import { generateFakeValue } from '@/workflow/workflow-variables/utils/generate/generateFakeValue';
import { generateRecordOutputSchema } from '@/workflow/workflow-variables/utils/generate/generateRecordOutputSchema';
import { type FieldMetadataType } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
+import {
+ type FormFieldLeaf,
+ type FormOutputSchema,
+} from 'twenty-shared/workflow';
export const generateFormOutputSchema = (
formFields: WorkflowFormActionField[],
@@ -34,7 +37,7 @@ export const generateFormOutputSchema = (
value: generateRecordOutputSchema(objectMetadataItem),
};
} else {
- result[formField.name] = {
+ const formFieldLeaf: FormFieldLeaf = {
isLeaf: true,
type: formField.type as FieldMetadataType,
label: formField.label,
@@ -42,6 +45,11 @@ export const generateFormOutputSchema = (
formField.placeholder ??
generateFakeValue(formField.type, 'FieldMetadataType'),
};
+ const selectedFieldId = formField.settings?.selectedFieldId;
+
+ result[formField.name] = isDefined(selectedFieldId)
+ ? { ...formFieldLeaf, fieldMetadataId: selectedFieldId }
+ : formFieldLeaf;
}
}
diff --git a/packages/twenty-shared/src/workflow/index.ts b/packages/twenty-shared/src/workflow/index.ts
index 16b6c6f9a64..c99eda8cc7e 100644
--- a/packages/twenty-shared/src/workflow/index.ts
+++ b/packages/twenty-shared/src/workflow/index.ts
@@ -218,6 +218,7 @@ export type {
FindRecordsOutputSchema,
IteratorOutputSchema,
FormFieldLeaf,
+ FormSelectFieldLeaf,
FormFieldNode,
FormOutputSchema,
CodeOutputSchema,
diff --git a/packages/twenty-shared/src/workflow/workflow-schema/index.ts b/packages/twenty-shared/src/workflow/workflow-schema/index.ts
index e3321b2cfcd..66d73b1e497 100644
--- a/packages/twenty-shared/src/workflow/workflow-schema/index.ts
+++ b/packages/twenty-shared/src/workflow/workflow-schema/index.ts
@@ -27,6 +27,7 @@ export type {
FindRecordsOutputSchema,
FormFieldLeaf,
FormFieldNode,
+ FormSelectFieldLeaf,
FormOutputSchema,
IteratorOutputSchema,
ManualTriggerOutputSchema,
diff --git a/packages/twenty-shared/src/workflow/workflow-schema/types/OutputSchema.ts b/packages/twenty-shared/src/workflow/workflow-schema/types/OutputSchema.ts
index d9a12c5b465..779b509d9e7 100644
--- a/packages/twenty-shared/src/workflow/workflow-schema/types/OutputSchema.ts
+++ b/packages/twenty-shared/src/workflow/workflow-schema/types/OutputSchema.ts
@@ -69,13 +69,20 @@ export type FormFieldLeaf = {
value: unknown;
};
+export type FormSelectFieldLeaf = FormFieldLeaf & {
+ fieldMetadataId: string;
+};
+
export type FormFieldNode = {
isLeaf: false;
label: string;
value: RecordOutputSchemaV2;
};
-export type FormOutputSchema = Record<string, FormFieldLeaf | FormFieldNode>;
+export type FormOutputSchema = Record<
+ string,
+ FormFieldLeaf | FormSelectFieldLeaf | FormFieldNode
+>;
export type CodeOutputSchema = BaseOutputSchemaV2;
diff --git a/packages/twenty-shared/src/workflow/workflow-schema/utils/__tests__/search-variable-in-output-schema.form.test.ts b/packages/twenty-shared/src/workflow/workflow-schema/utils/__tests__/search-variable-in-output-schema.form.test.ts
index 624ae828aed..51c956ade34 100644
--- a/packages/twenty-shared/src/workflow/workflow-schema/utils/__tests__/search-variable-in-output-schema.form.test.ts
+++ b/packages/twenty-shared/src/workflow/workflow-schema/utils/__tests__/search-variable-in-output-schema.form.test.ts
@@ -78,6 +78,13 @@ describe('searchVariableInOutputSchema - form output schema', () => {
label: 'Contact Email',
},
+ status: {
+ isLeaf: true,
+ type: FieldMetadataType.SELECT,
+ label: 'Status',
+ value: 'OPEN',
+ fieldMetadataId: 'status-field-metadata-id',
+ },
contactPerson: {
isLeaf: false,
label: 'Contact Person',
@@ -130,6 +137,22 @@ describe('searchVariableInOutputSchema - form output schema', () => {
});
});
+ it('should return the selected field metadata id of a select field', () => {
+ const result = searchVariableThroughFormOutputSchema({
+ stepName: 'Company Form',
+ formOutputSchema: mockFormSchema,
+ rawVariableName: '{{step1.status}}',
+ isFullRecord: false,
+ });
+
+ expect(result).toEqual({
+ variableLabel: 'Status',
+ variablePathLabel: 'Company Form > Status',
+ variableType: FieldMetadataType.SELECT,
+ fieldMetadataId: 'status-field-metadata-id',
+ });
+ });
+
it('should handle nested record field access correctly', () => {
const result = searchVariableThroughFormOutputSchema({
stepName: 'Company Form',
diff --git a/packages/twenty-shared/src/workflow/workflow-schema/utils/search-variable-in-output-schema.ts b/packages/twenty-shared/src/workflow/workflow-schema/utils/search-variable-in-output-schema.ts
index cd72f0c2e66..becd9741049 100644
--- a/packages/twenty-shared/src/workflow/workflow-schema/utils/search-variable-in-output-schema.ts
+++ b/packages/twenty-shared/src/workflow/workflow-schema/utils/search-variable-in-output-schema.ts
@@ -449,6 +449,8 @@ const searchThroughFormOutputSchema = ({
variableLabel: formField.label,
variablePathLabel: `${stepName} > ${formField.label}`,
variableType: formField.type,
+ fieldMetadataId:
+ 'fieldMetadataId' in formField ? formField.fieldMetadataId : undefined,
};
}