Can't Capturing and Displaying Ratings

Hello
I can’t set the ratings on the site.
I followed step by step, using the same variables (and database names), the Corvid guide.

I leave below the code I’m using.

When, in the preview, I click on it, it tells me:
Cannot read property ‘avg’ of null

CODE:


export function ratingsInput1_change_1(event) {
//Add your code for this event here:
$w(“#dataset1”).onReady(() => {
// get the current item from the dataset
const currentItem = $w(“#dataset1”).getCurrentItem();

// get the current average rating, number of ratings, and
//total ratings for the current dataset item
const average = currentItem.avg;
const count = currentItem.numRatings;
const total = currentItem.totalRatings;

// get the new rating from the ratings input
const newRating = $w(‘#ratingsInput1’).value;

// calculate the new average rating based on the current
//average and count
const newAverageLong = (total + newRating) / (count +1);
// Round the average rating to 1 decimal point
const newAverageShort = Number.parseFloat(newAverageLong).toFixed(1);

// set the dataset fields to the new average, total
// ratings, and number of ratings
$w(‘#dataset1’).setFieldValues({
‘avg’: newAverageShort,
‘totalRatings’: total + newRating,
‘numRatings’: (count + 1)
});

// save the dataset fields to the collection
$w(‘#dataset1’).save()
. catch ((err) => {
console.log(‘could not save new rating’);
});
});
}

I hope you can help me.

Have a nice day!

You are following this tutorial.
https://support.wix.com/en/article/corvid-tutorial-capturing-and-displaying-ratings

Have a read of the api reference as to why you are getting the null.
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#getCurrentItem

I tried to enter values directly in the table (with the panel) but nothing, it just does not want to work.

Is the code correct?