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 09:53 AM
Hi Sturton ,
Please re-check your code. You are updating on variable not on GlideRecord object which is 'gr1'.
Thanks
Ashish
Please hit helpful or correct , if it resolved the issue.
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 10:06 AM
Hello Ashish
Thanks for the response. Yes Im attempting to update the instance with the sum of the individual metric results. The field I want to to set is on the 'assmt_instance' record. Im sure Im way off. Heres my revised code, any help how it should be done?
----------------------------------------
(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.addAggregate('SUM','value');
gr1.query();
if(gr1.next()){
var ts = gr1.getAggregate('SUM','value');
assmt_instance.u_survey_total_score = ts;
assmt_instance.update();
}
if(assmt_instance.u_survey_total_score < 7){
gs.eventQueue('TCHC.survey.lowscore',current,gs.getUserID(),gs.getUserName());
}
})(current, previous);
----------------------------------------
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2018 10:21 AM
one question , why you are applying update() method on variable 'assmt_instance' as it contains the value of current.instance but its not a GlideRecord object.
On which table this BR is running ? Is that assmt_metric_result ?
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 10:37 AM
the update is working, I replaced:
var ts = gr1.getAggregate('SUM','value');
current.u_survey_total_score = ts;
with
current.u_survey_total_score = 8;
and the record updated as desired. The issue appears to be with the gr1.getAggregate('SUM','value');