What I’m trying to accomplish:
So basically I’ve created a custom form that retrieves inputs and adds them to the CMS and created a button that is supposed to trigger my backend code that generates a pdf of the inputs and retrieves the pdf url and displays it in the Triggered Email.
What is going wrong:
The button does send the email however no inputs are being displayed in the email i.e ${firstName} ${lastName} ${pdfLink}
Here’s my code:
$w.onReady(function () {
$w("#submit").onClick(() => {
const contactInfo = {
name: {
first: $w("#input50").value,
last: $w("#input51").value
},
emails: [{
email: $w("#input52").value
}],
phone: $w("#input53").value
};
contacts.appendOrCreateContact(contactInfo)
.then((resolvedContact) => {
if (resolvedContact) {
$w("#text154").expand();
const contactData = {
firstName: $w("#input50").value,
lastName: $w("#input51").value,
email: $w("#input52").value,
phone: $w("#input53").value
};
// Call the backend to generate the PDF and get the link
generatePdfAndSend(contactData)
.then(pdfLink => {
console.log("PDF generated and link is:", pdfLink);
const MY_ID = "keeping this clear for this topic";
triggeredEmails.emailMember('UXErZVE', MY_ID, {
variables: {
firstName: contactData.firstName,
lastName: contactData.lastName,
email: contactData.email,
phone: contactData.phone,
pdfLink: pdfLink
}
})
.then(() => {
console.log("Email sent to MY_ID");
})
.catch((err) => {
console.log("Error sending email to MY_ID:", err);
});
triggeredEmails.emailContact('thanksforsubmitting', resolvedContact.contactId, {
variables: {
firstName: contactData.firstName,
lastName: contactData.lastName,
email: contactData.email,
pdfLink: pdfLink
}
})
.then(() => {
console.log("Recipient email sent");
})
.catch((err) => {
console.log("Error sending recipient email:", err);
});
})
.catch(error => {
console.error("Error generating PDF:", error);
});
}
console.log("Contact created/updated:", resolvedContact);
})
.catch((error) => {
console.error("Error creating/updating contact:", error);
});
});
});