Like/Unlike SharePoint List Items from SharePoint Hosted App

To enable rating refer this article –

Code to update like:


 function setLike(likeFlag)
 SP.SOD.executeFunc('reputation.jsMicrosoft.Office.Server.ReputationModel.Reputation', function () {
 SP.SOD.executeFunc('sp.jsSP.ClientContext', UpdateLike(likeFlag));

 function UpdateLike(likeFlag) {
 var listId = "6d9e46c2-b396-4a4f-bc1f-6e265dfb6fe6"; //set list id and make sure rating is enabled in the list 
 var itemId = 3; //List Item Id 
 var ctx = new SP.ClientContext.get_current();
 Microsoft.Office.Server.ReputationModel.Reputation.setLike(ctx, listId, itemId, likeFlag); 
 ctx.executeQueryAsync(Function.createDelegate(this, this.RatingSuccess), Function.createDelegate(this, this.RatingFailure));

 function RatingSuccess(sender, args) {
 alert('Rating updated successfully');

 function RatingFailure(sender, args) {
 alert('Failed:' + args.get_message()); 

<button onclick="setLike(true)">Like</button>
<button onclick="setLike(false)">Unlike</button>

About Joseph Velliah
As a SharePoint Evangelist my professional interests tend to be technical and SharePoint focused. I run a blog at "SP RIDER" where you can expect to read HOW TOs and scenarios that I run into during my day to day job. I hope my posts will give back a little to the community that is helped me.

Comments are closed.

%d bloggers like this: