google-apps-scriptgoogle-sheetsgoogle-formsgoogle-form-quiz

Export questions and feedback from Google Forms to Google Sheets


I've learned here to create a script to import all questions from a Google Form to a Google Sheet.

What do I need to add to the script to export the feedback from each question as well?

I've tried this [in Alberto Vielma's script]:

var question = el.asMultipleChoiceItem();
var choices = question.getChoices();
sheet.getRange(question_position +1, 1).setValue(question.getTitle());
var i = 0;


for (i; i < choices.length; i++){
  sheet.getRange(answers_position + 1, 2).setValue(choices[i].getValue());
  sheet.getRange(answers_position + 1, 3).setValue(choices[i].isCorrectAnswer());
  sheet.getRange(answers_position + 1, 4).setValue(question.getFeedbackForCorrect());
  sheet.getRange(answers_position + 1, 5).setValue(question.getFeedbackForIncorrect());
  answers_position++;

but the two last colums just return "FreebirdFeedback" to the sheet, and not the actual feedback. What am I doing wrong?


Solution

  • Right now, you're just setting an instance of QuizFeedback as a value. If you want to retrieve the text that is shown to the user after they've submitted a response, you should use its getText() method:

    .setValue(question.getFeedbackForCorrect().getText());
    .setValue(question.getFeedbackForIncorrect().getText());
    

    Reference: