the backend is work correctly and i get status code 200 and also get a response with callId number.
The problem is that the contact don’t get the email.
I tried to run it on publish but still not working, another thing is that the contactId is undefined and i don’t know why.
thanks ahead
import { submitServiceCallBackend } from 'backend/formHandler';
import { triggeredEmails, contacts } from 'wix-crm-frontend';
$w.onReady(function () {
$w('#submitButton').onClick(() => {
$w('#message').text = 'Submitting...';
$w('#submitButton').disable();
const formData = {
Token: "TestServiceCall",
LicTradNum: $w('#license').value,
Subject: $w('#subject').value,
Description: $w('#description').value,
ContactPersonEmail: $w('#email').value,
ContactPersonName: $w('#name').value,
ContactPersonPhone: $w('#phone').value
};
console.log('Submitting form data:', formData);
submitServiceCallBackend(formData)
.then(response => {
console.log('Response received:', response);
if (response.status === 200) {
const callId = response.data.callId;
console.log('Success:', response.data);
$w('#message').text = `Thanks for submitting, your service Call ID is${callId}`;
contacts.appendOrCreateContact({
name: {
first: $w("#name").value,
},
extendedFields: {
callId: callId,
},
})
.then((contactInfo) => {
const contactId = contactInfo.contactId;
console.log("contact id:", contactId);
console.log('Contact created/updated:', contactInfo);
triggeredEmails.emailContact("serviceCallForm", contactId, {
variables: {
name: $w("#name").value,
callId: callId,
},
})
.then(() => {
console.log("Email sent");
})
.catch((error) => {
console.error("Failed to send email", error);
});
})
.catch((error) => {
console.error("Failed to create/update contact", error);
});
} else {
$w('#message').text = 'Submission failed. Please try again later.';
}
})
.catch(error => {
console.error('Catch block error:', error);
$w('#message').text = 'Submission failed. Please try again later.';
})
.finally(() => {
console.log('Request completed');
$w('#submitButton').enable();
});
});
});
New contributor
eyal yehiely is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.