imageThere are numerous cool new features in SharePoint 2010, and I’ve found that integrating them into custom solutions are not always straightforward.  I found this to be true with ratings as well.  Ratings are one of the new social tagging features that gives users a 1–5 star graphic to rate content.  You can find a high level overview of social tagging features here on TechNet.

Normally this isn’t a problem.  For example, you have your normal Shared Documents library, and you want users to be able to rate content.  No problem right?  We go into the library settings, and then click on Rating Settings.  We simple click Yes, and hit ok. Too easy:

SNAGHTML7778c9

This adds two site columns to the library called:

  • Number of Ratings
    • Stores the total number of ratings
  • Rating (0-5)
    • Stores the average rating of rated content

So everything’s working and dandy.  Well, what if we need ratings on a custom content type that is being deployed across the farm?  Who wants to go into every library and set that by hand?  There’s always PowerShell, but there’s a problem.  When I use the above normal library setting on a library with a custom content type, the ratings fail to get stored.  If you check the ULS logs, I saw this:

RatingSync: Unexpected exception processing <filename>. Error:Microsoft.SharePoint.SPException: Invalid number value. A number field contains invalid data. Please check the value and try again. ---> System.Runtime.InteropServices.COMException (0x8102001A): Invalid number value. A number field contains invalid data. Please check the value and try again.<nativehr>0x8102001a</nativehr><nativestack></nativestack>

Awesome.  So what do we do?  It’s really easy, we just need to add the rating columns to the custom content type itself.  To do this, edit your custom content type (located in the site content types gallery of the root site in the site collection most likely).  Click Add from existing site columns, and add the two columns named above.  After doing this, I was able to set ratings without error.  You HAVE to add them both or it won’t work!

Now, one last item of note on this.  Ratings are not stored instantly.  They work off of two timer jobs that are accessible via Central Administration on the SharePoint server:

  • User Profile Service Application – Social Data Maintenance Job
  • User Profile Service Application – Social Rating Synchronization Job

By default, they run hourly so your ratings changes wouldn’t show for an hour.  To speed this up, edit the timer job and change the schedule to some shorter minute value.  Or can you run them manually on demand for testing purposes.