feat: Salesforce - write to field without validation (#18722)
* Allow user to select custom field type * Get field value and write to field - ignoring field type * Only validate field length if present --------- Co-authored-by: Peer Richelsen <peeroke@gmail.com>
This commit is contained in:
co-authored by
Peer Richelsen
parent
da1b8137c2
commit
08e58851e7
@@ -57,6 +57,7 @@ const EventTypeAppCard: EventTypeAppCardComponent = function EventTypeAppCard({
|
||||
{ label: t("text"), value: SalesforceFieldType.TEXT },
|
||||
{ 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 },
|
||||
];
|
||||
|
||||
const [writeToPersonObjectFieldType, setWriteToPersonObjectFieldType] = useState(fieldTypeOptions[0]);
|
||||
|
||||
@@ -902,10 +902,8 @@ export default class SalesforceCRMService implements CRM {
|
||||
) {
|
||||
const conn = await this.conn;
|
||||
const { createEventOn, onBookingWriteToRecordFields = {} } = this.getAppOptions();
|
||||
|
||||
// Determine record type (Contact or Lead)
|
||||
const personRecordType = this.determinePersonRecordType(createEventOn);
|
||||
|
||||
// Search the fields and ensure 1. they exist 2. they're the right type
|
||||
const fieldsToWriteOn = Object.keys(onBookingWriteToRecordFields);
|
||||
const existingFields = await this.ensureFieldsExistOnObject(fieldsToWriteOn, personRecordType);
|
||||
@@ -930,7 +928,6 @@ export default class SalesforceCRMService implements CRM {
|
||||
organizerEmail,
|
||||
calEventResponses,
|
||||
});
|
||||
|
||||
// Update the person record
|
||||
await conn
|
||||
.sobject(personRecordType)
|
||||
@@ -970,6 +967,19 @@ export default class SalesforceCRMService implements CRM {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fieldConfig.fieldType === SalesforceFieldType.CUSTOM) {
|
||||
const extractedValue = await this.getTextFieldValue({
|
||||
fieldValue: fieldConfig.value,
|
||||
fieldLength: field.length,
|
||||
calEventResponses,
|
||||
bookingUid,
|
||||
});
|
||||
if (extractedValue) {
|
||||
writeOnRecordBody[field.name] = extractedValue;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle different field types
|
||||
if (fieldConfig.fieldType === field.type) {
|
||||
if (field.type === SalesforceFieldType.TEXT || field.type === SalesforceFieldType.PHONE) {
|
||||
@@ -1034,7 +1044,7 @@ export default class SalesforceCRMService implements CRM {
|
||||
bookingUid,
|
||||
}: {
|
||||
fieldValue: string;
|
||||
fieldLength: number;
|
||||
fieldLength?: number;
|
||||
calEventResponses?: CalEventResponses | null;
|
||||
bookingUid?: string | null;
|
||||
}) {
|
||||
@@ -1042,7 +1052,6 @@ export default class SalesforceCRMService implements CRM {
|
||||
if (!fieldValue.startsWith("{") && !fieldValue.endsWith("}")) return fieldValue;
|
||||
|
||||
let valueToWrite = fieldValue;
|
||||
|
||||
if (fieldValue.startsWith("{form:")) {
|
||||
// Get routing from response
|
||||
if (!bookingUid) return;
|
||||
@@ -1057,7 +1066,7 @@ export default class SalesforceCRMService implements CRM {
|
||||
if (valueToWrite === fieldValue) return;
|
||||
|
||||
// Trim incase the replacement values increased the length
|
||||
return valueToWrite.substring(0, fieldLength);
|
||||
return fieldLength ? valueToWrite.substring(0, fieldLength) : valueToWrite;
|
||||
}
|
||||
|
||||
private async getTextValueFromRoutingFormResponse(fieldValue: string, bookingUid: string) {
|
||||
@@ -1082,7 +1091,6 @@ export default class SalesforceCRMService implements CRM {
|
||||
// Search for fieldValue, only handle raw text return for now
|
||||
for (const fieldId of Object.keys(response)) {
|
||||
const field = response[fieldId];
|
||||
|
||||
if (field?.identifier === identifierField) {
|
||||
return field.value.toString();
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ export enum SalesforceFieldType {
|
||||
DATE = "date",
|
||||
TEXT = "string",
|
||||
PHONE = "phone",
|
||||
CUSTOM = "custom",
|
||||
}
|
||||
|
||||
export enum DateFieldTypeData {
|
||||
|
||||
Reference in New Issue
Block a user