Rate a article
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-02-2023 04:14 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-02-2023 07:14 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-05-2023 09:50 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-02-2023 10:52 AM
@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);