aftersave callback error: ItemID must be a string

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)
}

Hi Eb,

did you ever fix this? i’m having similar issues.

Cheers,
Glen

Have you checked out the tutorials for adding ratings and reviews to check your code is correct?
https://support.wix.com/en/article/corvid-tutorial-adding-ratings-and-reviews-to-a-wix-stores-site
https://support.wix.com/en/article/corvid-tutorial-capturing-and-displaying-ratings

As well as the onAfterSave code as well and making sure that you have got something to work with for your onAfterSave call, as if you are returned with an empty value which could be classed as null, then this null would not be a string and therefore you would be getting the error.
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#onAfterSave

Old post being closed, please add a new forum post if you are still having issues.