微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么在复选框中的“其他”选项中提交带有回复的谷歌表单没有反映在个人回复中?

如何解决为什么在复选框中的“其他”选项中提交带有回复的谷歌表单没有反映在个人回复中?

我正在尝试将 google 表格中的回复提交到 google 表单。我找到了脚本并对其进行了一些更改。

有一些带有“其他”选项的复选框字段。在 Google 表格中,某些问题的“其他”字段中有一些带有值的回复

我可以在摘要中看到“其他”回复。但我无法在个人回复中看到这些答案。 我也使用过 showOtherOption 方法,但我找不到解决方案。

这是我正在使用的脚本:

function readSpreadsheet() {
  var sheet = SpreadsheetApp.openById("123456");
  var range = sheet.getDatarange();
  var numRows = range.getNumRows();
  var values = range.getValues();
  var form = FormApp.getActiveForm();
  var items = form.getItems();
  for (var i = 2; i < numRows; i++) {
    var value = values[i];
    var formResponse = form.createResponse();
    var k = 1;
    for (var j = 0; j < items.length; j++) {
      var item;
      switch (items[j].getType()) {
        case FormApp.ItemType.LIST:
          item = items[j].asListItem();
          formResponse.withItemResponse(item.createResponse(value[k++]));
          break; 
        case FormApp.ItemType.MULTIPLE_CHOICE:
          item = items[j].asMultipleChoiceItem();
          var aa = value[k++];
          formResponse.withItemResponse(item.createResponse(aa));
          break; 
        case FormApp.ItemType.ParaGRAPH_TEXT:
          item = items[j].asParagraphTextItem();
          formResponse.withItemResponse(item.createResponse(value[k++]));
          break; 
        case FormApp.ItemType.TEXT:
          item = items[j].asTextItem();
          formResponse.withItemResponse(item.createResponse(value[k++]));
          break;
        case FormApp.ItemType.CHECKBox:
          item = items[j].asCheckBoxItem();
          var checkBoxValue = value[k++];
          if (typeof checkBoxValue !== 'string') {
              checkBoxValue = checkBoxValue.join(',');
          }
          var checkBoxValueArr = checkBoxValue.toString().split(/ *,*/);
          var choices = item.getChoices();
          var foundElem = [];
          var notFoundElem = [];
          checkBoxValueArr.forEach((elem) => {
            if(choices.map((choice) => choice.getValue()).indexOf(elem) != -1) {
              foundElem.push(elem);
            } else {
              notFoundElem.push(elem);
            }
          });
          if(notFoundElem.length > 0) {
            foundElem.push(notFoundElem.join(","));
          }
          item.showOtherOption(true);
          formResponse.withItemResponse(item.createResponse(foundElem));
          break;                 
        default:
          Logger.log("#" + (i + 1) + ":Do nothing for item " + j + " of type " + items[j].getType());
          continue;
      } 
      if(j==0){
        Logger.log("This item is the FORM NUMBER");        
      };
    }
    formResponse.submit();
    break;
  }
}

有没有其他方法可以让这些选项在个人回复中可见?

编辑:这是数据的示例格式。

Timestamp,Your name,Email ID,How old are you ?,Do you have any sources of income ?,How do you manage the money you earn ?,"Whom do you consult to manage your money apart from necessary expenses like rent,bills,etc ?",How well do you kNow about the ways you can save taxes ?,Can you share the reasons behind no kNowledge or basic kNowledge about taxes ?,Whom do you consult to invest your money ?,"In case you invest,what are challenges you've faced while trying learn and do it ?","In case you do not invest,what are the reasons you not to invest your money ?",Would you like to learn managing personal finances ?,Would you like to share your Feedback on managing your own personal finances ?

7/3/2021 0:17:20,Name1,Email1,23-30 Years old,Yes,Pay the bills and rent and keep remaining in savings accounts,Nobody. I don't manage the money I earn,"I have basic kNowledge. Example,80C","Difficulty to understand the rules,I don't have enough time to learn about it,I don't kNow where to learn about saving taxes",Nobody. I don't invest money,Not applicable for me,"Lack of kNowledge,I find the concepts difficult to understand,I find it risky,I don't kNow where to start",I wish to learn about financial literacy
7/3/2021 0:17:22,Name2,Email2,Friends/family,Less reliable sources of information,lack of awareness",Friends/Family,"Lack of relavant and structured material to study,I did not have anyone to discuss with about investments,I found too many options for investment confusing,Lack of reliable source of information,scams make someone lose interest in investing",I/My friends/relatives lost their money made me doubtful about investing,7/3/2021 0:17:24,Name3,Email3,"Pay the bills and rent and keep remaining in savings accounts,Invest in fixed deposit,Invest in mutual funds,Invest in stock market",Myself,Very well,I manage it on my own,Lack of relavant and structured material to study,No,7/3/2021 0:17:26,Name4,Email4,"Invest in fixed deposit,Invest in stock market,Invest in Tax saving schemes",I think I kNow the question there is no such option,A lot of time required to study a particular stock.,no

解决方法

这似乎是 Iamblichus 回答的问题。

有两种解决方法:

方法 A:使用预填充的 url 获取响应

entry.XXX=__other_option__&entry.XXX.other_option_response=answer

方法 B:通过 Google Apps 脚本为“其他”答案添加问题

  1. 在您的原始问题(即 itemOther)之后立即插入一个部分和一个文本问题(即 item),标题为空白的“其他”答案
  2. 跳转在 1. 中创建的部分以将其从 UI 提交中隐藏 Show form questions based on answers
  3. 您可能希望跳过 items 循环中的 (a) 分页符项目和 (b)“其他”问题

(a) 将 FormApp.ItemType.PAGE_BREAK 添加到您的 switch 参数

        case FormApp.ItemType.PAGE_BREAK:
          break;

(b) 在 if 参数前添加 switch 语句

      if (items[j].getTitle === '') continue;
  1. 修改代码以处理“其他”答案
let included = false;
for (const choice of item.getChoices()) {
  if (value[k++] === choice.getValue()) {
    included = true;
    break;
  }
}
if (included) {
  formResponse.withItemResponse(item.createResponse(value[k++]));
}
else {
  formResponse.withItemResponse(item.createResponse('__other_option__'));
  formResponse.withItemResponse(itemOther.createResponse(value[k++]));
}

showOtherOption(true) 用于在您添加或编辑问题时启用“其他”选项

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。