function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Amrith ThandraAmrith Thandra 

rating from different users

Hi Everyone,
i have a requirement
i am having two users with system administrator role , and having custom object with rating component , if user 1 is giving 5 rating and user 2 is giving 4 rating , then we need to take these two users value add them and show average of both
for example : user 1 rating = 5
                      user 2 rating = 4 

average rating =user1 rating + user 2 rating / 2 = 5+4/2

having rating__c(number) field & averagerating__c (text) field in custom object

different users with different records  on creating record need to show an average of  these ratings

for best example  , when we give rating for a movie in bookmyshow , we need to get rating average from different users and display the result

please let me know how to solve this
thanks in advance

please let me know if this is possible,
thanks in advance
GaurgkGaurgk
Hi Amrith,

As per my understanding,
custom object: Rating component
fields: rating__c= (Number type) and averagerating__c= (text) - readonly.
Assumption 1: only 1 user can rate in a record.
So, you need to write a trigger on Rating component.
step 1. fetch all the values of rating__c from all the records in a list.
step 2. averagerating__c = sum of all ratings/ total no of records.
step 3. insert averagerating__c.

Assumption 2: If there are multiple rating fields e.g rating1__c, rating2__c 
Assumption 3: user 1 will rate on rating1__c and user 2 will rate on rating2__c
step 2:  averagerating__c = sum of all ratings/(total no of records * no of fields)

Hope I am able to answer your doubt.
Amrith ThandraAmrith Thandra
hi gaurgk ,
thanks for reply

my exact requirement is ,
i have a custom object called competitor__c
in this custom object (competitor__c) there is a rating__c (number type) field , and i have created a lightning component called STAR RATING  which shows 5 stars,   whenever i give rating(from 1 to 5 )here  it is updated in Rating__c field ,

here is my task , for my org i am having 2 users(system administrators ) , i have logged into two orgs

custom object:  competitor__c
custom fields in object :  Rating__c (number type)  & AverageRating__c (text type)

two users user 1 , user 2 (system administrators)


when different users give rating on this custom object (rating component) , i need to get average of those rating and display in a field
(average rating_c)
  , i am new to this development , i dont have much idea on triggers ,

request you to please provide with a code if possible 
 i am also posting image for m,ore clear User-added image
thanks in advance
 
GaurgkGaurgk
Hi Amrith,

As per my assumption, AverageRating__c (text type) is in competitor__c(object). 
Every time one user creates a record and inserts Rating__c value, each time  AverageRating__c value get auto calculated?
If you are trying this approach, you might be wrong direction bcoz you need to update all the AverageRating__c for all the records which has previous got created which is not feasible. 

Its better you can consider this example approach to have better solution.
eg. Object1 : Movie(Name: Iron Man, AverageRating__c(formula))
Object2: User feedback(username: Amrith, rating__c: 4 , lookup(movie), username: gaurgk, rating__c: 3 , lookup(movie))
create formula field in movie, and you will get average of all ratings.

Sorry for the delay response.
Kesavarapu Gowtham 3Kesavarapu Gowtham 3

Hello
Amrith Thandra

 

I want a component to display star rating just like urs in aura application...coul you please let me know if you get any reference..