Hi everyone,
I have read most of the post about my problem (I found at least 2 with the same problem) however it looks like I tried everything mentionned so here I come.
I have an email template edited and published identified by ‘cedricMailId’
I have a dataset (“dataset1”) where all my guest inputdata is supposed to get saved (everything is configured “connected to data”)
However, the clic on the submit button does trigger an error instead of an email.
The code is a bit long as the message sent in the email depends on the guest choices so we are going through different test to create the email based on 4 parameters :
from_name, coming_status, coming_people, message
Here is my code :
import wixCRM from 'wix-crm';
import wixLocation from 'wix-location';
$w.onReady(function () {
//TODO: write your page related code here...
$w("#dataset1").onAfterSave(() => {
let from_name_value = $w("#input1").value;
let email = $w("#input2").value;
let coming_status_value = "";
let coming_people_value = "";
let message_value = "";
if($w("#radioGroup1").value==="NotCome"){
coming_status_value='I (we) Will not come for the wedding\n';
}
else if($w("#radioGroup1").value==="Maybe"){
coming_status_value='I (we) will MAYBE come for the wedding\n';
}
else if($w("#radioGroup1").value==="Come"){
coming_status_value='I (we) will come for the wedding';
}
let nameId = 3;
let dropDownId = 1;
while( nameId < 8 ){
let input = "#input"+nameId;
let name=$w(input).value;
if( name === "" || name === "Name")
break;
let dropDown = "#dropdown"+dropDownId;
let choice = $w(dropDown).value;
coming_people_value += "\n ---> Name: "+name+" & Dinner choice : "+choice+"\n";
nameId ++;
dropDownId ++;
}
let emails = [email];
wixCRM.createContact({
"firstName": from_name_value,
"emails": emails
})
.then(contactId => {
return wixCRM.emailContact('cedricMailId', contactId, {
variables: {
"from_name": from_name_value,
"coming_status": coming_status_value,
"coming_people": coming_people_value,
"message": message_value
}
})
.then( () => {
// do something after the email was sent
console.log("email sent \n reload the home page");
wixLocation.to(wixLocation.url);
})
.catch((err) => {
// handle the error if the email wasn't sent
console.log(`error : ${err}`);
})
})
})
})
After long debugging hours, it looks like everything is going well until its trying to send the email.
I had lots of console.log() that I removed to simplify the code and I can confirm that the contact Id is created and the code reach the emailContact function where the error is triggered.
My website editor link is : https://editor.wix.com/html/editor/web/renderer/edit/c1c16606-c887-4593-ad79-601a524dd03b?metaSiteId=d5dbe868-6d29-4727-953d-09c81decfff8&editorSessionId=f822c33a-0c08-4398-8d89-830437e3a6c2&referralInfo=dashboard
Thanks for your help. I’m giving up … already 6 hours after trying different third part services first and then finally get to wix intagrated mail service. I already figured that you can not call createContact() with a member of wix (myself) … this took me 2hours lol … so i’m using now the email from the input.
But the idea is to send the email to myself (and another one to the guest) … long work to get there