Data not saving to database (randomly)

Hi Wix team,

I’m looking for some advice, I have 2 datasets on my payment page to save data. One for ‘clients details’ and one for ‘course availability’ Both are on write only permissions.

When testing the page for saving, it always saves to both datasets, shows in the console.log but I have noticed that the ‘client details’ database sometimes isn’t updated with the details of the booking when someone has paid and around the 6 past bookings aren’t in the database.
‘Course availability’ has all of the details as it should just not ‘client details’ database. Can someone help please? Here is the relevant code in case I’m missing something.

‘Client Details’ Database

else {
                        pending = "‎£" + ($w("#amount").value - ($w("#deposit").value * $w("#amount").value));
                        $w('#datePicker1').value = participant1DOB;
                        $w('#courseAvailabilityDataset').save();
                        sendFormData().then(() => $w("#dataset9").save())
                            .then((item) => {
                                console.log("Saved Successfully in Database.");
                                $w('#paymentPreLoaderBox').hide();
                                $w('#slideshow1').changeSlide(4);
 
                            })
                            .catch((err) => {
                                console.log("Error while saving to the database.");
                                console.log(err.message);
                            });
                    }

‘Course Availability’ Database

export function paynow_click(event) {
    $w("#textFail").hide();
    changeState();
    payNow();
    $w('#paymentPreLoaderBox').show();
    $w('#courseAvailabilityDataset').setFieldValue('date', formattedDate)
    $w('#courseAvailabilityDataset').setFieldValue('courseId', courseID)
    $w('#courseAvailabilityDataset').setFieldValue('title', title)
    $w('#courseAvailabilityDataset').setFieldValue('numberOfParticipants', $w('#participantsOrder').value)
    $w('#courseAvailabilityDataset').setFieldValue('totalPrice', $w('#amount').value)
    $w('#courseAvailabilityDataset').setFieldValue('paymentReceived', $w('#textDeposit').value)
    $w('#courseAvailabilityDataset').setFieldValue('outstandingBalance', $w('#outstandingBalance').value)
    console.log(courseID)
    console.log(getDate)
    console.log(title)
    console.log($w('#outstandingBalance').value)
    console.log($w('#participantsOrder').value)
    console.log($w('#amount').value)
}


Thanks!

Anyone?

I don’t see a .save() in the paynow_click() function. How is it saving to the collection?

@yisrael-wix thank you for getting back to me, the .save is called in the paynow function (the code above the paynow_click()) Here is the full code if it helps. Sorry for not making this clear.

export function payNow(event) {
    createToken(encodeCard(createCard()))
        .then((token) => {
            console.log("Card token: " + token);
            tokenResponse = parseFloat(token);
            charge(token, payment)
 //charge($w("#token").value,payment)
                .then((chargeResponse) => {
                    console.log(chargeResponse);
 if (tokenResponse > 300) {
                        $w("#textFail").text = "There was an error with your card.\nPlease try again later or contact us.";
                        $w("#textFail").show();
                        console.log("There was an error with your card.");
                        $w('#paymentPreLoaderBox').hide();
                    } else {
                        pending = "‎£" + ($w("#amount").value - ($w("#deposit").value * $w("#amount").value));
                        $w('#datePicker1').value = participant1DOB;
                        $w('#courseAvailabilityDataset').save();
                        sendFormData().then(() => $w("#dataset9").save())
                            .then((item) => {
                                console.log("Saved Successfully in Database.");
                                $w('#paymentPreLoaderBox').hide();
                                $w('#slideshow1').changeSlide(4);
 
                            })
                            .catch((err) => {
                                console.log("Error while saving to the database.");
                                console.log(err.message);
                            });
                    }
                })
                .catch(() => {
                    $w("#textFail").text = "Please Complete All Fields";
                    $w("#textFail").show();
                });
        });
}

 export function paynow_click(event) {
    $w("#textFail").hide();
    changeState();
    payNow();
    $w('#paymentPreLoaderBox').show();
    $w('#courseAvailabilityDataset').setFieldValue('date', formattedDate)
    $w('#courseAvailabilityDataset').setFieldValue('courseId', courseID)
    $w('#courseAvailabilityDataset').setFieldValue('title', title)
    $w('#courseAvailabilityDataset').setFieldValue('numberOfParticipants', $w('#participantsOrder').value)
    $w('#courseAvailabilityDataset').setFieldValue('totalPrice', $w('#amount').value)
    $w('#courseAvailabilityDataset').setFieldValue('paymentReceived', $w('#textDeposit').value)
    $w('#courseAvailabilityDataset').setFieldValue('outstandingBalance', $w('#outstandingBalance').value)
    console.log(courseID)
    console.log(getDate)
    console.log(title)
    console.log($w('#outstandingBalance').value)
    console.log($w('#participantsOrder').value)
    console.log($w('#amount').value)
}

Thank you!

@yisrael-wix Do you have nay ideas? I am still having the same problem, when I test in preview and the live site it saves everytime, but it’s a little random when a user pays and it’s a lottery if the data is saved to the database. There is a custom form setup and the data send in this everytime, never missed any info (this is the function sendFormData )

Thank you

I have the exact same issue. My ibmexibmqc site under my ID Ibmretraitesqc has a collection named “ListeMembres” and my code saves the Dynamic form data to the collection. One out of 20 or 30 times, I am missing the entered data collected at the dynamic page. I know it was there because at the same time it saves to the collection, it also send an email with the content entered in the fields. Get all data in the email but not in the collection.

Any help!

Pierre Lacasse
ibmretraitesqc