Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 通过appscript比较google表单和google表单中的输入值_Google Apps Script_Google Sheets_Google Forms - Fatal编程技术网

Google apps script 通过appscript比较google表单和google表单中的输入值

Google apps script 通过appscript比较google表单和google表单中的输入值,google-apps-script,google-sheets,google-forms,Google Apps Script,Google Sheets,Google Forms,好的,我有一个谷歌表单,上面有一些东西要输入,比如说员工代码。当有人输入代码时,我需要将此代码与我在谷歌表单中的代码进行比较。是否可能(使用或不使用应用程序脚本)?如果可能的话,我需要相应地显示下一个表单。如果它是google表单中唯一的项目,那么如果它与工作表“ListOfCodes”第1列中的任何项目匹配,则此代码将返回true 我添加了这个代码来测试它,它工作得很好 function onFormSubmit(e) { const ss=SpreadsheetApp.getActive

好的,我有一个谷歌表单,上面有一些东西要输入,比如说员工代码。当有人输入代码时,我需要将此代码与我在谷歌表单中的代码进行比较。是否可能(使用或不使用应用程序脚本)?如果可能的话,我需要相应地显示下一个表单。

如果它是google表单中唯一的项目,那么如果它与工作表“ListOfCodes”第1列中的任何项目匹配,则此代码将返回true

我添加了这个代码来测试它,它工作得很好

function onFormSubmit(e) {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getSheetByName('ListOfCodes')
  const listofcodes=sh.getRange(1,1,sh.getLastRow()).getValues().map(function(r){return r[0];})
  var idx=listofcodes.indexOf(e.values[1]);
  if(idx!=-1) {
    Logger.log(idx)
    return true;
  }
}

您是如何运行它的?

您所说的“我需要相应地显示下一个表单”是什么意思?此外,请按照中的建议添加您的搜索/研究工作的简要说明。我以表格形式提交了“10010001”代码。现在我需要把它记录到谷歌表格上。如果代码匹配,那么在下一个表单中,我需要显示与此代码前五个字符匹配的员工列表作为答案。我在表单脚本中添加了此代码,因此我认为它没有找到电子表格。您询问过与输入的数据进行比较。你没有说要找一个电子表格,也没有发布任何代码。请发布您的代码并提供更好的解释。@Bista您应该将其添加到表单脚本中,而不是表单中。
function onFormSubmit(e) {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getSheetByName('ListOfCodes')
  const listofcodes=sh.getRange(1,1,sh.getLastRow()).getValues().map(function(r){return r[0];})
  var idx=listofcodes.indexOf(e.values[1]);
  if(idx!=-1) {
    Logger.log(idx)
    return true;
  }
}