need help for server side code using scheduled script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 03:45 AM
Hi ,
I am stucked with below script.
i have to calculate based on the employee details his performance and rank him accordingly.
employee_experience = per year 0.5 points
employee_appraisal =per quater 10 points(max 3 quater only)
rating = for last 2 years(Good = 4 points, Excellent = 6 points, Average = 2 points)
the above fields are available on my employee table.
I want below calculation.
Performance = employee_experience +employee_appraisal +rating
Ranking will be based on decreasing order of performance.
below is my scheduled job
var performance = '';
var empExp= current.employee_experience;
var empRating = current.rating;
var empAppraisal = current.employee_appraisal;
performance =empExp + empRating + empAppraisal;
current.update();
Not understanding how to calculate points, and give ranking.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 04:54 AM
current.update() isn't doing anything in this script as you have not updated any fields on the current record, so assuming performance is also a field on your employee table, you would at least need to change
current.performance = empExp + empRating + empAppraisal;
Running this as a scheduled job, I doubt there is a 'current' record, so you first need to do a GlideRecord query on the employee table for whatever criteria, or all records, then update each returned record. If you don't have a column to store performance on your employee table, then you can store it in the script with an identifier like name or whatever column, then print the results at the end. So something like this:
var objArr = [];
var gr = new GlideRecord('sn_employee_profile'); //whatever employee table you're using
//addQuery line(s) to limit results
gr.query();
while (gr.next()) {
objArr.push({
'employee' : gr.name.toString(),
'performance' : parseFloat(gr.employee_experience) + parseFloat(gr.rating) + parseFloat(gr.employee_appraisal)
});
}
objArr.sort(function(a,b) {
return b.performance - a.performance;
});
gs.print(objArr.join('\n'));