I have made a form that sends an email via triggered mails forms, and it is working fine, however i also want to make a form dataset collect the info into a collection too. Probblem is, when All is set and I click submit, the dataset runs first, and since it resets every input after submiting, the emails are arriving empty. is there a way to make the code that send the triggered email form run before the dataset start collecting, or add a delay to the dataset function?
I’ve been studying it, but if anyone can point me through the right direction, it will be much appreciated.
import { contacts } from 'wix-crm';
import { triggeredEmails } from 'wix-crm';
$w.onReady(function () {
$w("#submit").onClick(() => {
const contactInfo = {
name: {
first: $w("#name").value,
},
emails: [{
email: $w("#name").value
}]
};
contacts.appendOrCreateContact(contactInfo)
.then((resolvedContact) => {
if (resolvedContact) {
$w("#thanksText").show();
//send email to admin
const MY_ID = "<add admin ID here>";
triggeredEmails.emailMember('Tprof', MY_ID, {
variables: {
name: $w("#name").value,
endereco: $w("#endereco").value,
cidade: $w("#cidade").value,
estado: $w("#estado").value,
funcao: $w("#funcao").value,
email: $w("#email").value,
empresa: $w("#empresa").value,
cep: $w("#cep").value,
rg: $w("#rg").value,
resposta1: $w("#resposta1").value,
resposta2: $w("#resposta2").value,
resposta3: $w("#resposta3").value,
resposta4: $w("#resposta4").value,
resposta5: $w("#resposta5").value,
resposta6: $w("#resposta6").value,
resposta7: $w("#resposta7").value,
resposta8: $w("#resposta8").value,
resposta9: $w("#resposta9").value,
resposta10: $w("#resposta10").value,
resposta11: $w("#resposta11").value,
resposta12: $w("#resposta12").value,
resposta13: $w("#resposta13").value,
resposta14: $w("#resposta14").value,
resposta15: $w("#resposta15").value,
resposta16: $w("#resposta16").value
}
})
.then(() => {
console.log("email sent")
})
.catch((err) => {
console.log("error", err)
})
}
})
})
});