Default answer from script in Assessments

dng
Kilo Contributor

We have a requirement to default some of the answers on an assessment based on values from the Assessable record.  I have been playing with an option in the Assessment Metric method called “Default answer from script” which would insinuate that I could default the value in a custom script.  However I put the code below in the script and some variations of it with no success.  The logs seem to be printing properly with the right values but i’m not seeing the Assessment answer default to what I’m trying to set it to.  I am using the "Yes/No" data type right now, but I have also tried it with String and Number with no success.  Has anyone had experience with this or has any ideas about another way to set the Assessment answer default value on load?

 
 
 
// The following variables are available: 
 // - primary: contains the sys_id of the assessable object to be evaluated 
 // - string_result: the script sets the display string value for this metric to this variable 
 // - actual_result: the script sets the actual value for this metric to this variable 
 // - scaled_result: the script sets the scaled value (used in calculations) for this metric to this variable 
 // 
 // For example:
 // var gr = new GlideRecord('cmdb_ci');
 // gr.addQuery('manufacturer', primary);
 // gr.query();
 // actual_result = gr.getRowCount();
 // string_result = actual_result + '';
 // if (actual_result > 100) scaled_result = 5;
 // else scaled_result = 1;
 
 
var grRvcRec = new GlideRecord('x_case_review');
grRvcRec.addQuery('sys_id', primary);
grRvcRec.query();
if(grRvcRec.next()) {
    var reviewType = grRvcRec.getValue('review_type');
    var cr = 'Complex Review';
    gs.info('review found! review_type=' + reviewType);
    if(cr.indexOf(reviewType != -1)) {
        actual_result = 1;
        string_result = 'Yes';
        scaled_result = 1;
        gs.info('review Found! actual_result=' + actual_result);
    }
}
 
7 REPLIES 7

Joe Weisiger
Giga Expert

Hi dng, did you ever get this to work correctly?  I am trying the same and unsuccessful in getting the assessment question to display an answer.

jwalk_yota
Tera Expert

Hey DNG, did you ever find a solution for this? Doing something similar with risk identification assessments, and the values aren't quite acting right.

Clarice Ara_ez
Tera Contributor

Hi @dng I have the similar requirement to default answer based on script. Did you ever find solution for this?