I write down a JavaScript to reset news likes. It is working properly. But I need to checkOut the file while trying to edit news properties.
ResetNewsLike = function () {
var pagesListItem = this.opagesListItem.getEnumerator();
var list = this.list;
while (pagesListItem.moveNext()) {
var currentItem = pagesListItem.get_current().get_fieldValues();
var result = { ID: currentItem.ID };
var currentWeb = clientContext.get_web(); var ListItem = list.getItemById(result.ID);
var file = ListItem.get_file();
file.checkOut();
ListItem.set_item("LikedBy", "");
ListItem.set_item("LikesCount", 0);
file.checkIn();
ListItem.update();
clientContext.executeQueryAsync(Function.createDelegate(result, GetNewsComment), Function.createDelegate(this, Log.Error));
}
}
What did I try to solve this problem :
I tried to use approve method of file but It didn't work.
file.approve();
Then I tried to set _ModerationStatus but It didn't work too.
ListItem.set_item('_ModerationStatus', 0);
ListItem.update();
The question is what is the proper way to approve checkedOut file with JavaScript?