Sunday, October 9, 2011

Sharepoint 2010 Social Features: Rating Publishing Pages/Blog pages

1)Enable the publishing features in site collection/site level

In Page Library Settings-->Rating Setting -->Enable the Contents to be rated.
Edit the Page in Sharepoint Designer or modify the Pagelayouts.

2)Add the namespace
%@ Register TagPrefix="SharePointPortalControls" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %

3)Make sure that User Profile Service application is running in CA-->Manage Service applications
Add Rating Control  in Page Layout
SharePointPortalControls:AverageRatingFieldControl FieldName="Rating" runat="server"

Make sure that Field Name matches the Rating Column Name in Page Library.
4) To view the quick effects
CA > Monitoring > Timer Jobs > Review Job Definitions > look for 'User Profile Service Application - Social Data Maintenance Job' and 'User Profile Service Application - Social Rating Synchronization Job'.
Run the jobs.
5)If You get the Error 'Object reference not set to an instance' on viewing rated publishing Page
cmd-->inetmgr ->Restart SharePoint Web Services under Sites

Include the reference of JS file in Page Layouts
script type='text/javascript'
$(document).ready(function() {
var pathname = window.location;
var soapEnv ="soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>\
GetRatingOnUrl xmlns='http://microsoft.com/webservices/SharePointPortalServer/SocialDataService'>\
url>+ pathname + /url>\
/soap: Envelope>"
alert (soapEnv);
url: "http://servername/_vti_bin/SocialDataService.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=\"utf-8\""



function processResult(xData, status) {

var result = $(xData.responseXML).find("Rating")
//get rating value from webservice
var avg = parseFloat(result.text());

$(".ms-currentRating img").addClass(getClassNameForRating(avg));

function getClassNameForRating(rating) {
//apply class according  to ratings

rating = 0)

return "";

if (rating < 0.25)

return "ms-rating_0";

if (rating <; 0.75)

return "ms-rating_0_5";

if (rating <; 1.25)

return "ms-rating_1";

if (rating < 1.75)

return "ms-rating_1_5";

if (rating < 2.25)

return "ms-rating_2";

if (rating < 2.75)

return "ms-rating_2_5";

if (rating < 3.25)

return "ms-rating_3";

if (rating < 3.75)

return "ms-rating_3_5";

if (rating < 4.25)

return "ms-rating_4";

if (rating <; 4.75)

return "ms-rating_4_5";


return "ms-rating_5";



No comments: