Hello,
I’m trying to set up a simple triggered email at the moment. Please see the code below.
I have a subscribe automation which is firing correctly, but the triggered email keeps giving me the following error message:
wixCRM.createContact({
"firstName": $w("#firstName").value,
"lastName": $w("#lastName").value,
"company": $w("#companyName").value,
"email": $w("#email").value,
"description": $w("#description").value
})
.then((contactId) => {
console.log("Emailing now");
console.log(contactId);
wixCRM.emailContact('webinarRegistration', contactId, {
variables: {
participantName: $w("#firstName").value,
webinarDate: webinarDate,
webinarTitle: webinarTitle,
endTime: endTime,
startTIme: startTime
}
})
.then(() => {
console.log("Triggered email sent");
})
.catch((err) => {
console.log("This is not working");
console.log(err);
});
});
Use the on after save function, I use it on my code below and it all works fine
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#onAfterSave
import wixCRM from 'wix-crm';
$w.onReady(function () {
$w("#JoinUsForm").onAfterSave(() => {
let startDate = $w("#startDate").value;
let firstName = $w('#firstName').value;
let lastName = $w('#lastName').value;
let email = $w("#email").value;
let choirRole = $w("#choirRole").value;
let readMusic = $w("#readMusic").value;
let choirBefore = $w("#choirBefore").value;
let startNow = $w("#startNow").value;
wixCRM.createContact({
"firstName": firstName,
"lastName": lastName,
"emails": [email],
"Choir Role": choirRole,
"Read Music": readMusic,
"Choir Before": choirBefore,
"Start Now": startNow,
"Start Date": startDate
})
.then((contactId) => {
// Need to use the triggered email name
return wixCRM.emailContact('joiningusform', contactId, {
"variables": {
// Need to use the triggered email variable names
"firstName": firstName,
"email": email,
"choirRole": choirRole,
"readMusic": readMusic,
"choirBefore": choirBefore,
"startNow": startNow,
"startDate": startDate.toLocaleDateString('en-GB', { weekday: 'short', day: 'numeric', month: 'short', year: 'numeric'})
}
});
})
.catch((err) => {
// handle the error if the email wasn't sent
console.log(`Error: ${err}`);
});
});
});
I will try that but now the error message have changed to this, might be something wrong with the page, it is not event going to the second part of the function at this point:
Getting to the second part of the function now but still encountering CORS errors: