0

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?

  • Hi Onur, I think already somebody answer this question. could you please try this Stackexchange link .sharepoint.stackexchange.com/questions/102055/… – vinit kumar Sep 10 '18 at 7:37
  • Hi Vinit, I already tried that way, I tried it after ListItem.Update() and It says "The file is not checked out. You must first check out this document before making changes". If I try before ListItem.Update() It says "You cannot change moderation status and set other item properties at that same time" – Onur CAN Sep 10 '18 at 7:43
0

The problem was order of the methods. We need to update item first then we can approve it.

 file.checkOut();
 ListItem.set_item("LikedBy", "");
 ListItem.set_item("LikesCount", 0);
 ListItem.update();
 file.checkIn();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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