13 06 2013
Setting Page Ratings using SharePoint Client Object Model
Want to set the Rating for the current page yourself with JavaScript?
Here’s how. You will probably need to build your own rating control to get the rating for the current page and render it nicely, but until I figure out the SP JavaScript to update the OOTB control, here’s the code for actually setting the rating:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
(function () { var listId = _spPageContextInfo.pageListId; var itemId = _spPageContextInfo.pageItemId; var rating = 3; // Make sure you set this to what the user wanted EnsureScriptFunc('reputation.js',</pre> 'Microsoft.Office.Server.ReputationModel.Reputation', function() { var ctx = new SP.ClientContext(); rating = Microsoft.Office.Server.ReputationModel.Reputation.setRating(ctx, listId, itemId , rating); ctx.executeQueryAsync(done, fail); }); function done() { //alert("Done"); // Handle something here, like updating the UI of your rating control. } function fail() { //alert("Failed"); // If it fails for whatever reason, dump it in the console for debugging, // or tell the user } })(); |
SharePoint 2013 Design Manager – It Kinda Sucks, It’s Kinda Good Find SharePoint Pages That Use a Specific Page Layout
Thanks, it works great…
@Darshan are you able to update RatingCount ? I dont see its getting updated. Rating works. But not ratingcount. Have u faced this ?
[…] We are attempting to use the example located on this: Site […]