0

I've done some research however I cannot find anything similar to what I am trying to do.

Error that I've been receiving: TypeError: Cannot read property 'range' of undefined CheckHandleSteamIDNotation @ Code.gs:24 AddNewMembers @ Code.gs:10

Edit Link to the Copy of the Spreadsheet: https://docs.google.com/spreadsheets/d/1HGVTpBPiswkwTnfyJe0zzTOdtdtqKmEY-AZhxguDp70/edit?usp=sharing

The Google Apps Script Code is attached to the Sheet and should copy with it.

Here is the two code snippets as well seperately

function AddNewMembers(event){
  CheckHandleSteamIDNotation(event)
  SpreadsheetApp.flush();
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var recruitment_log = ss.getSheetByName('Recruitment Log');
  var main_roster = ss.getSheetByName('Main Roster');
  var isAdded = recruitment_log.getRange('R3').getValue();
  if(isAdded == "No") {
    var recruit_id = "'" + recruitment_log.getRange('J3').getValue();
    main_roster.getRange('I100').setValue(recruit_id);
  }
}

function CheckHandleSteamIDNotation(event)
{
  let formSheet = event.range.getSheet();
  let header = formSheet.getRange(1,1,1,formSheet.getMaxColumns()).getValues();
  let formRange = formSheet.getRange(formSheet.getLastRow(), 1, 1, formSheet.getMaxColumns());
  let formValues = formRange.getValues();
  for(let i = 0; i < header[0].length; i++)
  {
    if(header[0][i].includes("SteamID"))
    {
      formValues[0][i] = "'" + formValues[0][i];
    }
  }
  formRange.setValues(formValues);
}
Mwsmurf
  • 31
  • 3
  • From your showing script, it seems that your script is run using the event object. If you directly run your script, such error occurs because of no event object. Please be careful about this. For example, when you want to directly run your script, how about putting `event = {range: SpreadsheetApp.getActiveRange()}` just after the line of `function AddNewMembers(event){`? Or how about modifying `let formSheet = event.range.getSheet()` to `let formSheet = SpreadsheetApp.getActiveSheet()`? – Tanaike Sep 28 '22 at 23:53
  • Hi Tanaike, It appears that it fixes the error however the script does not function as intended. I'm at a complete loss on what could be making it not work. – Mwsmurf Sep 29 '22 at 00:05
  • Thank you for replying. From `It appears that it fixes the error`, I understood that your issue was resolved. About `however the script does not function as intended. I'm at a complete loss on what could be making it not work.`, I have to apologize for my poor English skill. Unfortunately, from your question and reply, I cannot understand your expected goal. By this, I cannot think of a solution. But, I would like to support you. So when I could correctly understand your expected goal, I would like to try to think of a solution. I deeply apologize that I cannot understand what you want to do. – Tanaike Sep 29 '22 at 00:10

0 Answers0