I am reusing code Sandy Good provided to answer a similar question about how to email various cells from a spreadsheet. I have 2 calling functions as follows:
function onFormSubmit() {
var sheet = getSpreadsheet().getSheetByName(RESPONSES_SHEET);
handler = SheetHandler(sheet);
handler.processSheet();
writeToLog();
};
function prepForPayrollEntry() {
var sheet = getSpreadsheet().getSheetByName(RESPONSES_SHEET);
handler = SheetHandler(sheet);
handler.generateListForPaychex();
};
The functions being called are both inside the Sheethandler() function:
function SheetHandler(sheet) {
var _sheet = sheet;
var _data = getRowsData(_sheet);
// Removed other functions not relevant to this code
var processSheet = function() {
_data.forEach(function(d) {
if(d.state == BLANK_STATE) {
_markPending(d);
}
});
}
var generateListForPaychex = function() {
var allRowsData = "";
var body = "",
payPeriod,
employeeName,
numberOfHours,
leaveType;
_data.forEach(function(d) {
if(d.state == APPROVED_STATE) { //Only list approved entries
payPeriod = d.payrollPeriod;
employeeName = d.yourName;
numberofHours = d.numberOfHoursRequested;
leaveType = d.typeOfLeave;
body = ""; //Reset on every loop
body = payPeriod + " " +
employeeName + " " +
numberOfHours + " " +
leaveType +
"\n";
allRowsData = allRowsData + body;
}
});
Logger.log(allRowsData);
MailApp.sendEmail(SETTINGS.APPROVAL_NOTICE_EMAIL_TO,SETTINGS.PAYCHEX_LIST_FOR_REVIEW,allRowsData);
}
The onFormSubmit() function works fine but when I run the prepForPayrollEntry() function I get an error saying TypeError: Cannot find function generateListForPaychex in object [object Object]. (line 542, file "Code").
The code I'm referencing came from Google Sheets content to email (lay out)
Would appreciate pointers on what I'm doing wrong.