通过appscript比较谷歌表单和谷歌表单中的输入值



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

如果它是谷歌表单中唯一的项目,那么如果它与Sheet第1列中名为"的任何项目匹配,则此代码将返回true;ListOfCodes";

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];})
if(listofcodes.indexOf(e.values[1])!=-1) {
return 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;
}
}

你是怎么运作的?

最新更新