Survey Responses - setting total score value for assessment instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2018 09:35 AM
Hello Community
Ive created a BR where im trying to sum all the response values on an individual assessment and set a 'total' field for the assessment, however it is not setting the value. Any help is much appreciated!!
(function executeRule(current, previous /*null when async*/) {
var assmt_instance = current.instance;
var gr1 = new GlideRecord('asmt_metric_result');
gr1.addQuery('instance',assmt_instance);
gr1.query();
var total = 0;
while (gr1.next());{
{
total = gr1.getAggregate('SUM','value');
assmt_instance.u_survey_total_score = total;
assmt_instance.update();
}
if(current.u_survey_total_score < 7){
gs.eventQueue('TCHC.survey.lowscore',current,gs.getUserID(),gs.getUserName());
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2018 10:42 AM
That's good , as 'current' is a object so it will work with update() method. That's why i was asking why you were doing update on script variable not on object.
Please hit helpful/correct , if it helps you.
Thanks.
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2018 11:44 AM
Figured it...needed to query with the sys_id
(function executeRule(current, previous /*null when async*/) {
var assmt_instance = current.sys_id;
var gr1 = new GlideAggregate('asmt_metric_result');
gr1.addQuery('instance',assmt_instance);
gr1.addAggregate('SUM','actual_value');
gr1.query();
while(gr1.next()){
ts = gr1.getAggregate('SUM','actual_value');
current.u_survey_total_score = ts;
current.update();
}
if(current.u_survey_total_score < 7){
gs.eventQueue('TCHC.survey.lowscore',current,gs.getUserID(),gs.getUserName());
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2018 11:49 AM
So your problem resolved.
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution