Hello! I am using a hook to insert data from a custom form into a database. I need to be alerted when a new task is submitted, and I would like a confirmation receipt to be sent to the user. My form is working inasmuch as the data is inserted into the database, but the triggered email is not working. The code I’ve pasted below is my attempt at sending the triggered email to the user. Can anyone help me fix this code AND add the code that will send me a copy of the same Triggered email? THANKS IN ADVANCE FOR YOUR HELP!
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
$w.onReady( function () {
let user = wixUsers.currentUser;
let userId = user.id; // “r5cme-6fem-485j-djre-4844c49”
let isLoggedIn = user.loggedIn; // true
user.getEmail()
.then( (email) => {
let userEmail = email; // “user@something.com”
} );
user.getPricingPlans()
.then( (pricingPlans) => {
let firstPlan = pricingPlans[0];
let planName = firstPlan.name; // “Gold”
let startDate = firstPlan.startDate; // Wed Aug 29 2018 09:39:41 GMT-0500 (Eastern Standard Time)
let expiryDate = firstPlan.expiryDate; // Thu Nov 29 2018 08:39:41 GMT-0400 (Eastern Daylight Time)
let date = startDate;
let day = date.getDate();
let month = date.getMonth()+1;
let year = date.getFullYear();
let dateStr = year + month + day;
console.log(dateStr); // show result in the developers console
$w(“#planId”).value = planName + “_” + dateStr;
} );
user.getEmail()
.then((email) => {
let userEmail = email;
$w(“#email”).value = userEmail;
});
$w("#submit").onClick(() => {
let toInsert = {
“firstName”: $w(“#firstName”).value,
“lastName”: $w(“#lastName”).value,
“companyName”: $w(“#companyName”).text,
“email”: $w(“#email”).value,
“clientId”: $w(“#clientId”).text,
“requestType”: $w(“#requestType”).text,
“requestDetails”: $w(“#comments”).value,
“clientUpload”: $w(“#uploadButton1”).value,
“clientUploadImage”: $w(“#uploadButton2”).value,
“planId”: $w(“#planId”).value
};
wixData.insert("taskForm", toInsert)
.then(() => {
wixLocation.to("/dashboard");
wixUsers.emailUser("vaTaskReceipt", userId, {
variables: {
“email”: $w(“#email”).value,
“firstName”: $w(“#firstName”).value,
“lastName”: $w(“#lastName”).value,
“companyName”: $w(“#companyName”).text,
“comments”: $w(“#comments”).value
}
} )
})
. catch ((err) => {
let errorMsg = err;
});
});
});