Want to alert on html from code of .gs file

Viewed 134

I have a Google Sheet, wep app - form and want to check the duplicate of input data.

If it's duplication, pop up alert on html page before sending data to Google Sheet.

But, alert() from [.gs file of Google Apps Script] seems doesn't work.

I want to alert when [if (position >-1) ] is true.

What am I missing? help me...

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;
  }
}
1 Answers
codeList.indexOf(userInfo.studentname); //the code that user input is a number

If userInfo.studentname is of Number type, then strict checking by indexOf will fail as codeList is a array of String types.

Try

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