1

I wish to reset the ratings for an item after a list item is edited. I can get the Average rating to be reset back to 0, but not the ratingCount. How can I do this?

The code I am using is

var context = new SP.ClientContext(_spPageContextInfo.webServerRelativeUrl);
var list = context.get_web().get_lists().getById(_spPageContextInfo.pageListId);

// test case is item 2 in my list

var item = list.getItemById(2);

context.load(item, "RatingCount", "AverageRating");
context.executeQueryAsync(RetrievedListID, ExecutionFailed);

function RetrievedListID(sender, args) {
var rc = item.get_item("RatingCount");
var ar = item.get_item("AverageRating");
item.set_item('AverageRating',0);
item.set_item('RatingCount',0);
item.update();

context.executeQueryAsync(RetrievedListID1, ExecutionFailed1);

function RetrievedListID1(sender, args) {alert('Done')};
function ExecutionFailed1(sender, args) {alert('Failed')};
 }

  function ExecutionFailed(sender, args) {
    alert('Failed');
  }
}

1 Answer 1

1

You have to reset the RatedBy column too iirc.

item.set_item('RatedBy',[]);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.