On the dynamic page, I am using a trigger email on the code when someone submits the form. The issue is only that when I try to send the trigger to site members ,it is not sending the automated email. It is giving this error: "error: server responded with - {“message”:“a member with these communication details (email / phone) already exists”,“details”:{“applicationerror”:{“code”:“permission denied”,“description”:“permission denied”}}} (403)**
Hey! Would you mind posting your code so we can have more context on the issue?
It is giving me error here when I am submitting the form.
async function onFormSubmit() {
//todo: error handling/displaying
if (!data) return;
if (!$w("#input6").valid || !$w("#input7").valid || !$w("#input8").valid || !$w("#textBox1").valid) return; //not a valid input
const name = $w("#input6").value;
const email = $w("#input7").value;
const subject = $w("#input8").value;
const message = $w("#textBox1").value;
let newEntry = {
name: name,
subject: subject,
email: email,
message: message,
property: data._id,
agent: data.agent._id
}
wixData.save('contactForm', newEntry)
.then(async (results) => {
console.log(results); //see item below
if (language === 'en') {
let res = await contactForm_afterInsert(newEntry, 'TrdF8Ok')
console.log('sent', res);
} else if (language === 'nl') {
let res = await contactForm_afterInsert(newEntry, 'TrdJuzZ')
console.log('sent', res);
}
$w('#text42').expand()
$w('#text43').collapse()
$w('#input6').value = "";
$w('#input7').value = "";
$w('#input8').value = "";
$w('#textBox1').value = "";
$w('#input6').resetValidityIndication();
$w('#input7').resetValidityIndication();
$w('#input8').resetValidityIndication();
$w('#textBox1').resetValidityIndication();
})
.catch((err) => {
console.log('save error',err);
$w('#text42').collapse()
$w('#text43').expand()
});
}
This is the backend code.
export async function contactForm_afterInsert(item, context) {
let agent = await wixData.get('Agents', item.agent);
let property = await wixData.get('Properties', item.property);
let contactId = agent.contactId;
console.log("contact id ", contactId);
if (!contactId) {
console.log("contact id not exist ", contactId);
// no contact id exists yet for this agent
contactId = await wixCrmBackend.createContact({
firstName: agent.name,
emails: [agent.email],
labels: ["Agent"]
});
agent.contactId = contactId;
wixData.update('Agents', agent);
}
let mailData = {
name: item.name,
email: item.email,
subject: item.subject,
message: item.message,
property: property.title
}
triggeredEmails.emailMember(context, contactId, {
variables: mailData
})
return item;
}