How to get total value of survey when survey submitted

Asha Pathak
Tera Contributor

I want to display total value of survey , means if there are values as very low, low ,high , very high, want a total count
Below is the script but not working correctly, Please help!

 

var test = new GlideRecord('asmt_assessment_instance');
test.addQuery('sys_id','2372c745c3a50210ceb0de1d050131a9');
test.query();
 if(test.next()){
    gs.print(test.number);
    var question = new GlideRecord('asmt_assessment_instance_question');
    question.addQuery('instance',test.sys_id);
    question.query();
 
      var totalScore = 0;
      var questionCount = 0;

// Loop through the questions and calculate the total score
while(question.next()) {
    var row = new GlideRecord('asmt_metric_definition');
    //define.addQuery('',);
    row.addQuery('category','Rockefeller Capital Management Customer Satisfaction Survey');
    row.addEncodedQuery('category=8403663297eff110132b37671153aff1^datatype=numericscale',question.metric);
    row.query();
    if(row.next()){

gs.print('in query count'+ row.getRowCount());
    }
    /*var response = question.getValue('response'); // Assuming response is the field where the response score is stored
    if (response != '') {
        totalScore += parseFloat(response);
        questionCount++;
    }
}

// Calculate the average
var averageScore = totalScore / questionCount;

// Print or use the average score as needed
gs.info('Average score of assessment instance questions: ' + averageScore);*/
    }

 }

5 REPLIES 5

Community Alums
Not applicable

Hi @Asha Pathak ,

If I get it right you can do like 

g_form.getValue("variable_name");

 

Please Mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak