Home>
I am making a seat reservation system with the answer spreadsheet of Google Form.

Although I was a beginner, I made it while searching for it, but I got the following error in the function to check for duplicate seats, so please help me.

Parameter () does not match the method signature of SpreadsheetApp.Sheet.getRange
Corresponding source code
function seatReservation () {
  // Read the specified spreadsheet (enter ID, open, specify sheet)
  var id ='';
  var spsheet = SpreadsheetApp.openById (id);
  var sheet1 = spsheet.getSheets () [0];
  var sheet2 = spsheet.getSheets () [1];
  // Get the last row of each sheet
  var sheet1_lastrow = sheet1.getLastRow ();
  var sheet2_lastrow = sheet2.getLastRow ();
  // Get the seat number from the record you just entered
  var nseat = sheet1.getRange (sheet1_lastrow, 7) .getValue ();
  // Search for rows with duplicate seat numbers
  // findRow (target seat, desired value (seat number), search target column) is declared at the bottom
  var rowPosition = findRow (sheet1, nestat, 7);
}
function findRow (sheet1, val, col) {
    var dat = sheet1.getRange (). getValue ();
    for (var i = 1;i<dat.length;i ++) {
    if (dat [i] [col-1] === val) {
      return i + 1;
    }
  }
    return 0;
}
What I tried

I referred to a certain site and rewrote it as var spsheet = SpreadsheetApp.getActiveSpredsheet (), but it didn't work. I'm a beginner, so I don't know where to play with, so I'm honestly out of luck ...
I'd like to make it work somehow, but if there is a solution, thank you.

Supplementary information (FW/tool version, etc.)

Please provide more detailed information here.

  • Answer # 1

    Parameter () does not match the method signature of SpreadsheetApp.Sheet.getRange

    This has no parameters (=()Can be called with)SpreadsheetApp.Sheet.getRangeBecause the method doesn't exist.

    findRowIn the method

    var dat = sheet1.getRange (). getValue ();

    Like, without parametersgetRangeIs calling, so there is an error here.

    getRange (row, column)
    https://developers.google.com/apps-script/reference/spreadsheet/sheet#getrangerow,-column
    * There are other patterns of arguments to receive, so please check the link destination.


    If the entire range of data is covered, insteadgetDataRangePlease use.

    Sheet.getDataRange ()
    https://developers.google.com/apps-script/reference/spreadsheet/sheet#getdatarange

  • Answer # 2

    const q305535 = () =>{
        const id ='';
        const book = SpreadsheetApp.openById (id);
        const sheets = book.getSheets ();
        const sheet1 = sheets [0] .getDataRange (). getValues ​​();
        const needle = sheet1.slice (-1) [6];
        const isDuplicated = sheet1.map (e =>e [6]). includes (needle);
    }

    I open the sheet with id, but if the code is in the range I can see now, I think it is better to make it a container bound script and process it with onEdit.

  • Answer # 3

    Thank you, draq.
    When I did the following, the error disappeared in this part.

    function findRow (sheet1, val, col) {
         var id ='';
         var ss = SpreadsheetApp.openById (id);
         var sheet1 = ss.getSheets () [0];
    // This represents ALL the data
    var range = sheet1.getRange ('G2: G');
    var values ​​= range.getValues ​​();
       var dat = sheet1.getRange ('G2: G'). getValues ​​();
        for (var i = 1;i<dat.length;i ++) {
        if (dat [i] [col-1] === val) {
          return i + 1;
        }
      }
        return 0;
    }

Related articles