Rate a article

Siri Namamula
Tera Contributor

Hi 

I have a requirement in which a user should be able to give star rating between 1 to 5 only once.

Now a user is able to give star rating to a article multiple times

3 REPLIES 3

Aniko Hegedus
Tera Expert

Hi,

 

Maybe you could put a before insert business rule to the Knowledge Feedback (kb_feedback) table, something roughly like this:
var user = gs.getUserID();
var article = current.article;

var feedbackGR = new GlideRecord("kb_feedback");
feedbackGR.addQuery("article", article);
feedbackGR.addQuery("user", user);
feedbackGR.addQuery("rating", "!=", "0");
feedbackGR.query();
if(feedbackGR.next()) {
gs.addErrorMessage("Can't rate again");
current.setAbortAction(true);
}

Aniko

Hi @Aniko Hegedus 

It is working but when I am giving rating in portal it is getting executed for comments as well I want it only for star rating

NotNowBoss
Tera Guru

@Siri Namamula 

Hello,

I made one so that you can only rate an article once if it has been updated since your last rating.
First i would make an advanced on before insert business rule with the following code
Remember to add when to run conditions so it does not always run:

User is dynamic Me

Rating greater than 0

(function executeRule(current, previous /*null when async*/ ) {
    var grFeedback = new GlideRecord("kb_feedback");
    grFeedback.addQuery("article", current.article);
    grFeedback.addQuery("user", gs.getUserID());
    grFeedback.addQuery("rating", "!=", 0);
    if (grFeedback.get()) {
        var grArticle = new GlideRecord("kb_knowledge");
        if (grArticle.get(current.article)) {
            if (grArticle.sys_updated_on < grFeedback.sys_created_on && grArticle.workflow_state == "published") {
                gs.addErrorMessage("Your Text here");
                current.setAbortAction(true);
            }
        }
    }
})(current, previous);