Pages

Monday 29 December 2014

Like and Unlike update list Item using Javascript

 update likes / Unlike
     function updatelike(Itemid) {      
            //get mentioned list id
             var listid = GetListId("Posts");
             //like updated for blogs
             EnsureScriptFunc('reputation.js', 'Microsoft.Office.Server.ReputationModel.Reputation', function () {
                 var aContextObject = new SP.ClientContext();
                 Microsoft.Office.Server.ReputationModel.Reputation.setLike(
                 aContextObject,
                 listid,
                 Itemid,
                 true);
                 //put your like successed or not
                 aContextObject.executeQueryAsync(function () {
                     alert('like successed');                
                 }, function (sender, args) {
                     alert('like failed');                
                 });
             });
         }

get list id
        function GetListId(listName) {
            var id = "";
     
            $().SPServices({
                operation: "GetList",
                listName: listName,
                async: false,
               // webURL: rootSite,
                completefunc: function (xData, Status) {
                    id = $(xData.responseXML).find("List").attr("ID");
                }
            });
            return id;
        }   

No comments:

Post a Comment