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();
}