From f24e8d12f05aa43216404cb59a3abe8fe7488210 Mon Sep 17 00:00:00 2001 From: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Date: Tue, 25 Mar 2025 08:05:30 +0900 Subject: [PATCH] feat: Salesforce - handle picklist field type (#20342) * Add picklist to `SalesforceFieldType` enum * Add picklist value to Salesforce settings * Add `getPicklistFieldValue` method * Find picklist option based on active and value --- apps/web/public/static/locales/en/common.json | 1 + .../components/EventTypeAppCardInterface.tsx | 3 +- .../app-store/salesforce/lib/CrmService.ts | 55 +++++++++++++++++++ packages/app-store/salesforce/lib/enums.ts | 1 + 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index bab3543d5c..9a727851b9 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -3036,5 +3036,6 @@ "tip_username_plus": "Tip: You can a '+' between usernames: cal.com/anna+brian to make a dynamic group meeting", "user_has_no_team_yet": "You don't have a team yet", "no_team_members": "You don't have team members yet", + "picklist": "Picklist", "ADD_NEW_STRINGS_ABOVE_THIS_LINE_TO_PREVENT_MERGE_CONFLICTS": "↑↑↑↑↑↑↑↑↑↑↑↑↑ Add your new strings above here ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑" } \ No newline at end of file diff --git a/packages/app-store/salesforce/components/EventTypeAppCardInterface.tsx b/packages/app-store/salesforce/components/EventTypeAppCardInterface.tsx index 0085a4d12f..9f6dbcba8e 100644 --- a/packages/app-store/salesforce/components/EventTypeAppCardInterface.tsx +++ b/packages/app-store/salesforce/components/EventTypeAppCardInterface.tsx @@ -8,9 +8,9 @@ import type { EventTypeAppCardComponent } from "@calcom/app-store/types"; import { WEBAPP_URL } from "@calcom/lib/constants"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { SchedulingType } from "@calcom/prisma/enums"; -import { InputField } from "@calcom/ui/components/form"; import { Alert } from "@calcom/ui/components/alert"; import { Button } from "@calcom/ui/components/button"; +import { InputField } from "@calcom/ui/components/form"; import { Select } from "@calcom/ui/components/form"; import { Switch } from "@calcom/ui/components/form"; import { showToast } from "@calcom/ui/components/toast"; @@ -63,6 +63,7 @@ const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({ { label: t("date"), value: SalesforceFieldType.DATE }, { label: t("phone").charAt(0).toUpperCase() + t("phone").slice(1), value: SalesforceFieldType.PHONE }, { label: t("custom"), value: SalesforceFieldType.CUSTOM }, + { label: t("picklist"), value: SalesforceFieldType.PICKLIST }, ]; const [writeToPersonObjectFieldType, setWriteToPersonObjectFieldType] = useState(fieldTypeOptions[0]); diff --git a/packages/app-store/salesforce/lib/CrmService.ts b/packages/app-store/salesforce/lib/CrmService.ts index bd517e48ec..8f22c3a2fc 100644 --- a/packages/app-store/salesforce/lib/CrmService.ts +++ b/packages/app-store/salesforce/lib/CrmService.ts @@ -1151,6 +1151,18 @@ export default class SalesforceCRMService implements CRM { writeOnRecordBody[field.name] = dateValue; continue; } + } else if (field.type === SalesforceFieldType.PICKLIST) { + const picklistValue = await this.getPicklistFieldValue({ + fieldConfigValue: fieldConfig.value, + salesforceField: field, + calEventResponses, + bookingUid, + contactId, + }); + if (picklistValue) { + writeOnRecordBody[field.name] = picklistValue; + continue; + } } } @@ -1294,6 +1306,49 @@ export default class SalesforceCRMService implements CRM { return null; } + private async getPicklistFieldValue({ + fieldConfigValue, + salesforceField, + calEventResponses, + bookingUid, + contactId, + }: { + fieldConfigValue: string; + salesforceField: Field; + calEventResponses?: CalEventResponses | null; + bookingUid?: string | null; + contactId: string; + }) { + const log = logger.getSubLogger({ prefix: [`[getPicklistFieldValue] ${contactId}`] }); + + const picklistOptions = salesforceField.picklistValues; + if (!picklistOptions || !picklistOptions.length) { + log.warn(`No picklist values found for field ${salesforceField.name}`); + return null; + } + + // Get the text value from the field + const fieldTextValue = await this.getTextFieldValue({ + fieldValue: fieldConfigValue, + fieldLength: salesforceField.length, + calEventResponses, + bookingUid, + }); + + if (!fieldTextValue) { + log.warn(`No text value found for field ${salesforceField.name}`); + return null; + } + // Get the picklist value from the field + const picklistValue = picklistOptions.find((option) => option.active && option.value === fieldTextValue); + if (!picklistValue) { + log.warn(`No picklist value found for field ${salesforceField.name} and value ${fieldTextValue}`); + return null; + } + + return picklistValue.value; + } + private async fetchPersonRecord( contactId: string, existingFields: Field[], diff --git a/packages/app-store/salesforce/lib/enums.ts b/packages/app-store/salesforce/lib/enums.ts index 9d66ba306b..7839e23fbd 100644 --- a/packages/app-store/salesforce/lib/enums.ts +++ b/packages/app-store/salesforce/lib/enums.ts @@ -14,6 +14,7 @@ export enum SalesforceFieldType { TEXT = "string", PHONE = "phone", CUSTOM = "custom", + PICKLIST = "picklist", } export enum DateFieldTypeData {