【发布时间】:2021-02-25 17:24:57
【问题描述】:
我有一个 Google 表格、wep 应用程序 - 表单并想检查输入数据的重复。
如果是重复的,在将数据发送到 Google Sheet 之前,在 html 页面上弹出警报。
但是,[Google Apps 脚本的.gs 文件] 中的alert() 似乎不起作用。
我想在 [if (position >-1) ] 为真时发出警报。
我错过了什么?帮帮我……
function addItem(userInfo) {
var ss = SpreadsheetApp.openByUrl(url);
var ws = ss.getSheetByName('Sheet1');
var data = ws.getRange(2, 4, ws.getLastRow(), 1).getValues();
var codeList = data.map(function(r) {
return r[0].toString();
});
var position = codeList.indexOf(userInfo.studentname); //the code that user input is a number
if (position > -1) {
var m1 = userInfo.studentname;
sendTelegram('"' + m1 + 'no' + '"');
return true;
} else {
ws.appendRow([
userInfo.bzpatteacher,
userInfo.bzperiod,
userInfo.seatnum,
userInfo.studentname,
userInfo.reginm,
new Date(),
]);
return false;
}
}
【问题讨论】:
-
欢迎来到Stack Overflow。另一方面,代码不包含
alert()函数,不清楚“Google Sheet,wep app - form”是什么意思。请添加minimal reproducible example。 -
我会考虑检查
addItem()中的重复项,如果发现返回消息到withSuccessHandler(),消息可以告诉用户天气是否重复。 -
嗨!您能否也分享一个您的 HTML 文件样本没有敏感数据?获得警报的一种方法是在 HTML 文件中使用
script标记,该标记从.gs文件中的触发器侦听。当您的 Apps 脚本文件中的条件匹配时,您的 HTML 中的脚本将检测满足的条件,并可以从您的 HTML 文件中触发alert()。谢谢 ! :D
标签: javascript html google-apps-script web-applications