2

Currently, I am developing a custom web part to show star rating for documents, everything is done.

However,when user hover on the star I want a tooltip message("Your current rating is 1..."), similar to what we have in libraries(or what the sharepoint by default provides in libraries).

So can I get the user specific rating depending upon the logged in user using code(.net or CSOM anything will work)?

2

How to get Social Rating for List Item via CSOM (JacaScript)

function getItemRating(listTitle,itemId, success,error)
{
    var context = new SP.ClientContext.get_current();
    var web = context.get_web();
    var list = web.get_lists().getByTitle(listTitle);
    var item = list.getItemById(itemId);

    context.load(item);
    context.executeQueryAsync(
        function() {
            var ratingEntry = {};
            ratingEntry.AverageRating = item.get_item('AverageRating');
            ratingEntry.RatingCount = item.get_item('RatingCount');
            ratingEntry.Ratings = item.get_item('Ratings');
            success(ratingEntry);           
        },
        function(sender,args)
        {
            error(args.get_message());
        }
    );
}

//Usage
getItemRating('Documents',5,function(ratingEntry){
    console.log(JSON.stringify(ratingEntry)); 
},
function(error){
    console.log(error);
});

Please refer How To Use CSOM with Ratings in SharePoint 2013 for a more details.


Another option would be to utilize SocialDataService Web Service using SPServices, the following operations are available:

0

There are two methods on SocialRatingManager, one to retrieve all rating given the URL and another to retrieve all rating given by a user. Documented here:

http://msdn.microsoft.com/en-us/library/office/microsoft.office.server.socialdata.socialratingmanager.getratings(v=office.15).aspx

See the code sample here

using (SPSite site = new SPSite("SharePoint site URL"))
{
SPServiceContext context = SPServiceContext.GetContext(site);
UserProfileManager myUserProfileManager = new UserProfileManager(context);
UserProfile myUserProfile = myUserProfileManager.GetUserProfile(false);
SocialRatingManager mySocialRatingManager = new SocialRatingManager(context);
SocialRating[] ratings = mySocialRatingManager.GetRatings(myUserProfile);
Console.WriteLine("Ratings for user:");
foreach (SocialRating rating in ratings)
{
   Console.WriteLine(rating.Url + ": " + rating.Rating);
}
}
1
  • thanks for the reply...Can this be done using ECMA script COM – Rameez Mar 23 '14 at 15:07

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.