首页 > 解决方案 > 想要从 .gs 文件的代码中提醒 html

问题描述

我有一个 Google 表格、wep 应用程序 - 表单并想检查输入数据的重复项。

如果是重复的,请在将数据发送到 Google 表格之前在 html 页面上弹出警报。

但是,alert()从 [.gs 文件的 Google Apps 脚本] 似乎不起作用。

我想在 [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;
  }
}

标签: javascripthtmlgoogle-apps-scriptweb-applications

解决方案


codeList.indexOf(userInfo.studentname); //the code that user input is a number

如果userInfo.studentnameNumber类型,那么严格检查indexOf将失败,因为codeListString类型数组。

尝试

var position = codeList.indexOf(userInfo.studentname.toString());

推荐阅读