SEE COMMENTS FOR SOLUTION
I have code where I insert into table 1, then update table 2 on submit. I am doing this directly in the code, not tied to a dataset (see below).
Does anyone know how I can use something similar to the .onAfterSave(sendFormData) directly from a table and not a dataset to send an email (using sendGrid)?
Thank you in advance!
export function submit_click(submitEvent) {
let quantity = $w("#nbrVolQuantity").value
if (!$w('#txtFirstName').valid ||
!$w('#txtLastName').valid ||
!$w('#txtEmail').valid ||
!$w('#nbrVolQuantity').valid ||
!$w('#txtPhone').valid) {
$w('#txtError').text = "One or more fields are not valid";
$w('#txtError').show();
return;
} //close function submit_click
//Make sure not entering a larger quantity than is available
if (parseFloat(quantity) > eventDetail.available){
$w('#txtError').text = "Please correct the Quantity below";
$w('#txtError').show();
return;
}
var data = {
"first_name": $w('#txtFirstName').value,
'last_name': $w('#txtLastName').value,
'title': $w('#txtEmail').value,
'phone': $w('#txtPhone').value,
'quantity':$w('#nbrVolQuantity').value,
'comments':$w('#txtComments').value,
'ped_title':eventDetailId, // This is "title" field which is referenced in VOLUNTEERS collection and the row I want to later update
}; //close var data
wixData.insert('PFA_VOLUNTEERS', data).
then((results) => {
results.fulfilled = results.fulfilled + parseInt($w('#nbrVolQuantity').value,10)
console.log("insert results ",results);
if (!eventDetail.fulfilled) { eventDetail.fulfilled = parseFloat(quantity)} else { /// in case you do not already have 0
eventDetail.fulfilled = parseFloat(eventDetail.fulfilled) + parseFloat(quantity) // in case it is a string not a number
}
wixData.update('PFA_EVENT_DETAIL', eventDetail).
then(update => console.log("Updated! : " , eventDetail))
.catch( err => console.log("Error while updating : " , err))
$w('#dsEventDetail').refresh();
console.log("update results ",results);
});
$w('#txtError').hide();
$w('#txtSuccess').show();
$w("#txtFirstName").value = null;
$w("#txtLastName").value = null;
$w('#txtEmail').value = null;
$w('#txtPhone').value = null;
$w('#nbrVolQuantity').value = null;
$w('#txtComments').value = null;
$w("#txtSelectedPosition").value = null;
}