1

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?

2 Answers 2

3

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.

3
  • This is excellent .Awesome !Cant believe so cool idea . Commented Dec 2, 2012 at 11:41
  • Hi @MohithKumar, thanks :) To be fair it's a well documented thing, except as usual it's "you need to know which keyword to look for", heh. "Advanced formulas examples": help.salesforce.com/apex/… - I guess that's why the files sit in "samples" dir?
    – eyescream
    Commented Dec 2, 2012 at 11:47
  • 2
    On this page Stars for Ratings you'll find a formula for rating stars. Go to the section named Stars for Ratings. This should have been a comment on @eyescream's answer, but I can only post this as an answer because of insufficient reputation points! Commented Apr 16, 2015 at 14:06
0

I always user the raty.js library for this. Just upload the library as a static resource and then you can customize the number of stars you need. You can pass in logic to determine the number of stars or just hard code it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .