# Ratings getcurrentitem always returns 0 index. setcurrentitem doesn't seem to work.

**URL:** <https://forum.wixstudio.com/t/ratings-getcurrentitem-always-returns-0-index-setcurrentitem-doesnt-seem-to-work/38752>\
**Category:** Ask the community\
**Tags:** code, wix-blog, question\
**Created:** [November 2, 2019, 6:56pm UTC](https://forum.wixstudio.com/t/ratings-getcurrentitem-always-returns-0-index-setcurrentitem-doesnt-seem-to-work/38752 "2019-11-02T18:56:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bingeverse](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/bingeverse/32/15582_2.png) [@bingeverse](https://forum.wixstudio.com/u/bingeverse)\
**Post date:** [November 2, 2019, 6:56pm UTC](https://forum.wixstudio.com/t/ratings-getcurrentitem-always-returns-0-index-setcurrentitem-doesnt-seem-to-work/38752/1 "2019-11-02T18:56:43Z")

</div>

I have a ratings input element(ratingsInput1) on my blog posts page. For each blog I want to capture a rating. How do I link the blog post ID to my ratings #Dataset1.

Here’s my code.

$w.onReady( () =\> {  
$w(“#dataset1”).onReady( () =\> {  
**let** num= $w(“#dataset1”).getCurrentItemIndex();  
console.log(“OnReady---------- Done setting Ratings current item " + num + " .”);  
} );

```
$w("#dataset1").setCurrentItemIndex(3) 
  .then( () => { 
    console.log("OnReady---------- Done setting Ratings current item " + 3 + " ."); 
  } ); 

```

} );

export function ratingsInput1\_change\_1(event) {

$w(“#dataset1”).onReady(() =\> {  
// get the current item from the dataset

**const** currentItem = $w(“#dataset1”).getCurrentItem();  
**let** num=5;  
$w(“#dataset1”).setCurrentItemIndex(num);

**const** currentItemidx = $w(“#dataset1”).getCurrentItemIndex();  
console.log(“==========On change Current Item index = " + currentItemidx + " .”);  
// 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’);  
});  
});  
}

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [November 2, 2019, 10:23pm UTC](https://forum.wixstudio.com/t/ratings-getcurrentitem-always-returns-0-index-setcurrentitem-doesnt-seem-to-work/38752/2 "2019-11-02T22:23:10Z")

</div>

Wix Blog is a Wix app and it is only limited access for working with Corvid.

This is what you can currently do.  
[https://www.wix.com/corvid/example/custom-feed](https://www.wix.com/corvid/example/custom-feed)  
[https://www.wix.com/corvid/example/related-posts](https://www.wix.com/corvid/example/related-posts)

These are the Wix Blog Collections that you have access to work with.  
[https://support.wix.com/en/corvid-by-wix/wix-blog-with-corvid](https://support.wix.com/en/corvid-by-wix/wix-blog-with-corvid)

Wix Blog does already have a like count that you can access in code.  
[https://support.wix.com/en/article/corvid-wix-blog-posts-collection-fields#like-count-likecount-1](https://support.wix.com/en/article/corvid-wix-blog-posts-collection-fields#like-count-likecount-1)

#### **Like Count (likeCount)**

**Description** : The number of likes the post received (from members only).  
**Type** : Number  
**Can connect to data** : Yes  
**Can use in dynamic page URL** : No  
**Can be sorted** : Yes  
**Can be filtered** : eq, ne, lt, lte, gt, gte  
**Read-only** : Yes

**Note**  
Like Count data used on your site pages may require up to 24 hours to update. To make sure new post likes are included on your site in real time, [disable caching](https://support.wix.com/en/article/caching-your-sites-pages) for any page that uses Like Count data.  
Note that disabling caching may increase your page loading time.

The like count can already be turned on and off on either desktop and mobile editor already in the Wix Blog settings.

Finally, note that the code sample you have used for your page is only intended to be used with the ratings element that is on the page, it isn’t designed to be interjected with anything else.  
[https://support.wix.com/en/article/corvid-tutorial-capturing-and-displaying-ratings](https://support.wix.com/en/article/corvid-tutorial-capturing-and-displaying-ratings)
