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
This commit is contained in:
Joe Au-Yeung
2025-03-24 23:05:30 +00:00
committed by GitHub
parent 19712f62e3
commit f24e8d12f0
4 changed files with 59 additions and 1 deletions
@@ -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 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑"
}
@@ -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]);
@@ -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[],
@@ -14,6 +14,7 @@ export enum SalesforceFieldType {
TEXT = "string",
PHONE = "phone",
CUSTOM = "custom",
PICKLIST = "picklist",
}
export enum DateFieldTypeData {