thanks in advance for your time. I am new to google apps scripting, so apologies if the question below is a basic one.
I have created functions for a sheet, which individually seem to run just fine. When both functions are combined, only one actually runs while the other doesn't work.
I'm hoping for some help as I'm sure the way that I have both laid out is incorrect.
Please see examples below.
function onEdit(){
autoNotes();
moveTabs();
}
function autoNotes() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet = ss.getActiveSheet()
var lr = sheet.getLastRow()
var data = sheet.getRange("A3:AQ"+lr).getValues()
var activeCell = sheet.getActiveCell()
var col = activeCell.getColumn()
var row = activeCell.getRow()
var mailAddress = data\[row-3\]\[11\]
var instructorName = '\<b\>Instructor: \</b\>'+ data\[row-3\]\[1\] + ' ' + data\[row-3\]\[2\]
var instructorFirst = '\<b\>\</b\>'+ data\[row-3\]\[1\]
var instructorFirstLast = data\[row-3\]\[1\] + ' ' + data\[row-3\]\[2\]
var instructorCourse = "\<b\>Course Build Training Track: \</b\>"+ data\[row-3\]\[5\] + ', ' + data\[row-3\]\[6\]
var totalDays = data\[row-3\]\[28\].toFixed(1)
var programrepFirstLast = data\[row-3\]\[10\]
var instructorEmail = data\[row-3\]\[3\]
var totalPercent = Number(data\[row-3\]\[29\]).toLocaleString(undefined, { style: "percent", minimumFractionDigits: 0,})
var formatDate1 = new Date(data\[row-3\]\[7\]).toLocaleDateString()
var courseDate = '\<b\>Course Start Date: \</b\>'+ formatDate1
var courseDate2 = formatDate1
var formatDate = new Date(data\[row-3\]\[27\]).toLocaleDateString()
var startDate = '\<b\>Training Start Date: \</b\>'+ formatDate
var startDate2 = formatDate
var urlsheet = "https://docs.google.com/spreadsheets/d/1DI074UNhvj_LNM35bb9WTsf9aFkxsTcmjOWnNT3nXts/edit?usp=sharing"
var recipients = mailAddress
var body = instructorName + '\\n' + instructorCourse + '\\n' + instructorFirst + '\\n' + startDate + '\\n' + courseDate + '\\n' + totalDays + '\\n' + programrepFirstLast + '\\n' + totalPercent + '\\n' + instructorEmail + '\\n' + startDate2 + '\\n' + courseDate2
// var contentHTML = "<body><p>"+ instructorName + "</p><p>" +instructorCourse + "</p><p>" +startDate + "</p><p><br> <a href='" + urlsheet + "'>MASTER Enrollment Sheet</a> </p><br> </body>"
if(row\>2 && col == 31 && activeCell.getValue()==true){
var subject = data\[row-3\]\[1\] + ' ' + data\[row-3\]\[2\]+ ' Training Update: Attended Kick-Off Meeting'
var contentHTML ="\<br\>" + instructorName + "\<br\>" + instructorCourse + "\<br\>" + courseDate + "\<br\>" + startDate + "\<br\>\<br\>" + "\<b\>Training Update:\</b\>" + "\<br\>\<br\>" + "Dear " + programrepFirstLast + "," + "\<br\>\<br\>" + "Instructor " + instructorFirstLast + " has attended the Canvas Course Development Kick-off Meeting with an instructional designer. The instructor has approximately \<b\>" + totalDays + " weeks\</b\> from their course start date to participate in training and build their Canvas course." + "\<br\>\<br\>" + "Next steps: \<ul\>\<li\>The instructor will use their personalized \<b\>Action Plan checklist\</b\> and reference the \<b\>CSGCB course\</b\> to learn Canvas and build relevant course elements.\</li\>\<li\>The instructor can attend live training sessions held each week to learn more about using Canvas, Zoom, and Panopto for video recording. \</li\>\<li\>The instructor can contact ATLI with questions at any point as they work their way through the Action Plan. \</li\>\</ul\> You will receive the next training update when " + instructorFirst + " completes the first set of major milestone tasks in the Action Plan." + "\<br\>\<br\>\<br\>" + "\<span style='background-color: #daebfd; font-size: 16px; padding: 1px;'\>\<b\>Please do not reply to this message via e-mail.\</b\> This address is automated, unattended, and cannot help with questions or requests. For assistance, contact UCLA Extension Learning Support at " + "\<b\>\<a href='mailto:atli@uclaextension.edu'\>atli@uclaextension.edu\</a\>\</b\>\</span\>." + "\<br\>\<br\>"
MailApp.sendEmail(recipients, subject, body,{htmlBody: contentHTML})
ss.toast("Email notification has been sent successfully.",'Status')
return
}
function moveTabs() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = e.source.getActiveSheet();
var r = e.source.getActiveRange();
if(s.getName() == "InProgress" && r.getColumn() == 35 && r.getValue() == "Y") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Completed");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
}
Just hoping to get both functions to work. Right now, combined, only the top function works and triggers an email to go out.