Cannot call method "getRange" of undefined Error. Very new to Scripts. No idea what this means!

591 views
Skip to first unread message

Kyle Gellatly

unread,
Nov 4, 2014, 10:30:18 AM11/4/14
to adwords...@googlegroups.com
I'm very new to scripts. Just looking to see if anyone has an idea of what this error I'm getting is talking about!

TypeError: Cannot call method "getRange" of undefined. (line 43)


I've highlighted where line 43 is. In my spreadsheet I have 3 sheets in it, so is that it? or do I have to put the name of the spreadsheet in here? In my script I have provided a link to the spreadsheet (not shown here), but I just have no idea what this means. Any help would be greatly appreciated! Thank you so much.


/**
 * The code to execute when running the script.
 */
function main() {
  // Load data from spreadsheet.
  var spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
  var campaignRuleData = getSheetData(spreadsheet, 1);
  var weatherConditionData = getSheetData(spreadsheet, 2);
  var geoMappingData = getSheetData(spreadsheet, 3);

  // Convert the data into dictionaries for convenient usage.
  var campaignMapping = buildCampaignRulesMapping(campaignRuleData);
  var weatherConditionMapping =
      buildWeatherConditionMapping(weatherConditionData);
  var locationMapping = buildLocationMapping(geoMappingData);

  // Apply the rules.
  for (var campaignName in campaignMapping) {
    applyRulesForCampaign(campaignName, campaignMapping[campaignName],
        locationMapping, weatherConditionMapping);
  }
}

/**
 * Retrieves the data for a worksheet.
 * @param {Object} spreadsheet The spreadsheet.
 * @param {number} sheetIndex The sheet index.
 * @return {Array} The data as a two dimensional array.
 */
function getSheetData(spreadsheet, sheetIndex) {
  var sheet = spreadsheet.getSheets()[sheetIndex];
  var range = sheet.getRange(2, 1, sheet.getLastRow() - 1, sheet.getLastColumn());
  return range.getValues();
}

Anash Oommen

unread,
Nov 5, 2014, 9:11:02 AM11/5/14
to adwords...@googlegroups.com
Hi Kyle,

Looks like this is a part of the Bid by Weather script. Did you alter the spreadsheet in any way after making a copy of the template spreadsheet?

Cheers,
Anash P. Oommen,
AdWords Scripts Team.
Message has been deleted

Anash Oommen

unread,
Nov 7, 2014, 3:05:39 PM11/7/14
to adwords...@googlegroups.com
Hi Kyle,

Could you use the "Reply to Author" option to share your customer id and script name?

Cheers,
Anash P. Oommen,
AdWords Scripts Team.
Reply all
Reply to author
Forward
0 new messages