Set Field Values Then Send (Grid) Email Not Working

Hello Wix Team!

Trying to set field values and then send email on submission. The field values get set to database but email won’t send through. If I remove the set field values in red the form submits. When I add them the fields update but form does not submit.

Here’s my code: Anyone could tell me what I’m missing here?
I appreciate your time.

export function button47_click(event) {
$w(“#dynamicDataset”).onReady( () => {
$w(‘#dynamicDataset’).setFieldValue(‘confirmed’, $w(‘#text384’).text);
$w(‘#dynamicDataset’).save();
$w(‘#text85’).show();

$w( ‘#dynamicDataset’ ).onReady(sendFormData);

function sendFormData() {
const subject = Vehicle Service Confirmed For ${$w( "#input7" ).value};
const body = `Dear ${$w( “#text306” ).text},

Your booking is confirmed!

Thank you **for** choosing our garage.

Your appointment details are as follows:

Scheduled Date:

${$w( "#text293" ).text}+${$w( "#input14" ).value}

Scheduled Time:

${$w( "#input1" ).value}

Get directions on the link below. See you soon!

Kind Regards,

Login

Email Us

Visit Website

Get Directions

${$w( "#shopteltext" ).text}

Location:

${$w( "#garagestreetaddress" ).text}

${$w( "#garagecityprovince" ).text}

${$w( "#garagepostalcode" ).text}

`; const recipient = $w( "#input2" ).value; sendEmailWithRecipient(subject, body, recipient) .then(response => console.log(response));

sendEmail(subject, body)
.then(response => console.log(response));
}
})
}

Remove the dynamicDataset.onReady().
(both of them).
They are not in the right place (they shouldn’t be inside an onClick event handler. Because they usually trigger before the click.

You can make the button disabled on load, and then:

$w.onReady(() => {
$w('#dynamicDataset').onReady(() => {
$w('#button47').enable();
})
})
//do not put it inside the onclick event handler

Also you forgoot to use () when you call the function.
it should be: sendFormData()

Hey-ho J.D. :wink: (o.k. i will leave now )
Your turn :grin: