[SalesForce] how to show the images of article ratings and most viewed articles

I am currently displaying all the articles based on search results and certain business conditions in a VF page. When displaying the articlelist i am using <knowledge:articleList> which is all working fine but i also need to display the article rating and View count for which I am currently querying on KnowledgeArticleVoteStat and KnowledgeArticleViewStat to get the count.

The problem is i am getting the count as integer from this query and need to convert this integer number into a image with the star options as displayed in the standard article page. I also tried articletoolbar option but it works only for article detail page, but i need this in the list view of articles. I just need to convert the integer count to standard sfdc article rating image, can any point me whats the best approach for this?

Best Answer

I don't have Knowledge available in my org but I suspect the ratings look like star icons on bottom of http://blogforce9dev-developer-edition.ap1.force.com/salesforceicons ?

3 stars

If that's the case you can simply take <img src="/img/samples/stars_300.gif" /> and convert it to <img src="/img/samples/stars_{!article.KnowledgeArticleVoteStat}00.gif" />.

I have no idea if range of this int is 0 to 5, sorry. if it can be bigger - just play with scaling it down to thresholds as you see fit, for example {!MIN(5, CEILING(article.KnowledgeArticleVoteStat / 50))} (here's the reference for math functions you can use). Whatever logic you might decide is needed & which you can express in formula fields syntax that will end up being a 0-5 number.


P.S. There are some questions here that warn us that directory structure, filenames etc aren't a "supported API" so Salesforce can change them anytime and then your customization breaks. To play it safe you might decide to upload these images as your own static resource.

Related Topic