I can not figure out how to fix this error. It shows up after I submit my form within my Lightbox. I have read through the articles on here but I can not make a connection. Any suggestion would be appreciated.
An error occurred in one of afterSave callbacks Error: ItemId must be a string.
//-------------Imports-------------//
import wixWindow from 'wix-window';
import wixData from 'wix-data';
//-------------Global Variables-------------//
// Current product's ID.
let businessName;
//-------------Lightbox Setup-------------//
$w.onReady(function () {
// Get the data passed by the page that opened the lightbox.
businessName = wixWindow.lightbox.getContext();
// Set the action that occurs before the review is saved.
$w('#submitReviews').onBeforeSave(() => {
// If no rating was set:
if ($w('#radioRating').value === '') {
// Display an error message.
$w('#rateError').show();
// Force the save to fail.
return Promise.reject();
}
// If a rating was set, set the element values into the fields of the dataset item.
// These values will be saved in the collection.
$w('#submitReviews').setFieldValues({
businessName,
rating: $w('#radioRating').value,
recommends: $w('#radioGroup1').value
});
});
// Set the action that occurs after the review is saved.
$w('#submitReviews').onAfterSave(async () => {
// Update the product's statistics using the updateStatistics() function.
await updateStatistics($w('#radioGroup1').value);
// When the statistics have been updated, close the lightbox to return the user to the product page.
wixWindow.lightbox.close();
});
});
// Update (or create) the product statistics.
async function updateStatistics(isRecommended) {
// Get the review statistics for the current product from the "reviewStats" collection.
let stats = await wixData.get('reviewStats', businessName);
// If statistics data already exist for this product:
if (stats) {
// Add the new rating to the total rating points.
stats.rating += parseInt($w('#radioRating').value, 10);
// Increase the ratings count by 1.
stats.count += 1;
// Increase the recommendations by one if the user recommends the product.
stats.recommended += (isRecommended === "true") ? 1 : 0;
// Update the new product statistics in the "reviewStats" collection.
return wixData.update('reviewStats', stats)
}
//If no statistics data exists for this product, create a new statistics item.
stats = {
// Set the statistics item's ID to the current product's ID.
_id: businessName,
// Set the statistics item's rating to the rating entered by the user.
rating: parseInt($w('#radioRating').value, 10),
// Set the statistics item's ratings count to 1 because this is the first rating.
count: 1,
// Set the statistics item's recommended property to 1 if the user recommends the product.
recommended: (isRecommended === "true") ? 1 : 0
};
// Insert the new product statistics item into the "reviewStats" collection.
return wixData.insert('reviewStats', stats)
}