I am updating multiple collections from form submission. My question is how to code having just a single success or failure message after all the insert events have completed? Appreciate any advice that would point me in the right direction.
My code:
export function formSubmit_click(event, $w) {
const toInsert1 = {
'company': $w("#companyName").value,
'contactFN': $w("#firstName").value,
'contactLN': $w("#lastName").value,
'contactEmail': $w("#email").value,
'contactTel': $w("#telephone").value,
'contactPos': $w("#position").value,
'contactAddr': $w("#address").value,
'contactPrevprac': $w("#prevAcc").value,
'contactPrevacc': $w("#prevaccName").value,
'contactPrevtel': $w("#prevaccTel").value,
'contactPrevemail': $w("#prevaccEmail").value,
'contactPrevaddr': $w("#prevaccAddress").value,
'contactNoprev': $w("#noPrevacc").checked
};
const toInsert2 = {
'company': $w("#companyName").value,
'compUTR': $w("#companyUTR").value,
'compVAT': $w("#vatRegistration").value,
'compVATdate': $w("#effecVATdate").value,
'compVATscheme': $w("#schemeVAT").value,
'compEmpl': $w("#emplReference").value,
'compCIS': $w("#contractorNumb").value,
'compAuth': $w("#chAuth").value,
'compSoftw': $w("#softwareYN").value,
'compSname': $w("#softwName").value,
'xHelp': $w("#xeroHelp").value,
'xHelpdetail': $w("#helpDetail").value
};
wixData.insert("clients", toInsert1)
.then( (results) => {
let items = results;
})
.catch( (err) => {
let errorMsg = err;
});
wixData.insert("system", toInsert2)
.then( (results) => {
let items = results;
})
.catch( (err) => {
let errorMsg = err;
});
}