Creating Populated email from Javascript - javascript

I want to start off by saying I have no idea what I am doing with HTML and Javascript but I am trying to learn. What I am creating will not be hosted by any server , it is more of a HTML web form(I think that is what i would call it) for employees to fill out and create a standardized email. I have 97% of it working but need a little help with the last part. Below is the Javascript that works:
function populateEmail() {
let bl = document.getElementById("blurb").value;
let a = document.getElementById("reg").value;
let b = document.getElementById("lvl").value;
let c = document.getElementById("node").value;
let i = document.getElementById("cust").value;
let d = document.getElementById("rea").value;
let e = document.getElementById("ma").value;
let f = document.getElementById("start_dt").value.replace("T", " ");
let g = document.getElementById("poc").value;
let h = document.getElementById("appr").value;
let m_to = "DL-ListOne; DL-ListTwo; DL-ListThree"
let m_cc = "DL-ListFour; DL-ListFive;"
let today = new Date();
let dd = String(today.getDate()).padStart(2, '0');
let mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
let yyyy = today.getFullYear();
today = mm + '/' + dd + '/' + yyyy;
let notify = document.getElementById("notify_lvl").value;
if (notify == "Initial"){
let deap = "Activation ";
}
else if (notify == "Update"){
let deap = "Update ";
}
else{
let deap = "De-Activation ";
}
document.location.href = "mailto:" + encodeURIComponent(m_to) + "?cc=" + encodeURIComponent(m_cc)
+ " &subject=DEAP " + encodeURIComponent(b) + ": Any Region " + today
+ " "
+ "&body="
+ "%0D%0A%0D%0A"
+ encodeURIComponent(bl) + "%0D%0A%0D%0A"
+ "Name: " + encodeURIComponent(a) + "%0D%0A"
+ "Activation – (" + encodeURIComponent(b)
+ "Current Impact = " + encodeURIComponent(c) + " modules, " + encodeURIComponent(i) + " customers) %0D%0A"
+ "Reason: " + encodeURIComponent(d) + "%0D%0A"
+ "Event Geographical Area: " + encodeURIComponent(e) + "%0D%0A"
+ "Event Start: " + encodeURIComponent(f) + "%0D%0A"
+ "POC: " + encodeURIComponent(g) + "%0D%0A"
+ "Approved by: " + encodeURIComponent(h) + "%0D%0A"
}
Now when I try and add the Variable deap to the subject line it stops creating the email. Here are the different ways I have tried to add it.
+ " &subject=DEAP " + deap + encodeURIComponent(b) + ": NE Region " + today
+ " &subject=DEAP " + encodeURIComponent(deap) + encodeURIComponent(b) + ": NE Region " + today
then I thought that maybe I had to add some text or space in there to have it take affect so I tried adding + " " + after the variable deap
I am trying to keep the post to a minimum, if you need my ugly looking HTML I will be happy to post it
but I am still trying to figure out how to load div from Javascript so my code isn't DRY.
Thank you in advance for your time

It's because you're declaring deap inside your if statements:
if ('notify' == "Initial") {
let deap = "Activation ";
} else if ('notify' == "Update") {
let deap = "Update ";
} else {
let deap = "De-Activation ";
}
console.log(deap);
If you declare it outside and reassign it inside your if blocks, it should work:
let deap;
if ('notify' == "Initial") {
deap = "Activation ";
} else if ('notify' == "Update") {
deap = "Update ";
} else {
deap = "De-Activation ";
}
console.log(deap)

Related

How to display today and 5 days with a counter and pass variables from build report down to the build alert function?

How to make "funding breakdown" show today and the next five business days without removing the “totalfunding” of just today and adding a counter to the “fundingbreakdown” so it comes out numbered?
I am passing through my variables from build report down to the build alert function, but for some reason, it is not passing the values from my variables. Why is that happening?
I appreciate your patience as this is my very first googleappscript.
function buildreport() {
const ss = SpreadsheetApp.getActive();
let data = ss.getSheetByName('February 2023').getRange("A:M").getValues();
var PrimorNonPrim = ss.getSheetByName('February 2023').getRange("A:A").getValues();
var Regionandentity = ss.getSheetByName('February 2023').getRange("B:B").getValues();
var Currency = ss.getSheetByName('February 2023').getRange("D:D").getValues();
var Amount = ss.getSheetByName('February 2023').getRange("F:F").getValues();
var RequestDate = ss.getSheetByName('February 2023').getRange("K:K").getValues();
var BankAcctCreditDate = ss.getSheetByName('February 2023').getRange("L:L").getValues();
var PayDate = ss.getSheetByName('February 2023').getRange("M:M").getValues();
let payload = buildAlert(data);
sendAlert(payload);
}
function buildAlert(data,PrimorNonPrim,Regionandentity,Currency,Amount,RequestDate,BankAcctCreditDate,PayDate) {
let today = new Date();
let filteredData = data.filter(row => {
let requestDate = new Date(row[10]);
return requestDate.getFullYear() === today.getFullYear() &&
requestDate.getMonth() === today.getMonth() &&
requestDate.getDate() === today.getDate();
});
let totalfunding = filteredData.reduce((total, row) => total + row[5], 0);
if (filteredData.length === 0) {
let fundingBreakdown = "Nothing coming up within 5 working days";
} else {
fundingBreakdown = (PrimorNonPrim + " " +"Entity" + " " + Regionandentity + " " + "Currency" + " " + Currency + " " + "Amount" + " " + Amount + " " + "Request Date" + " " + RequestDate + " " + "Bank Account Credit Date" + " " + BankAcctCreditDate + " " + "Pay Date" + " " + PayDate)}

GoogleSheets script to sendEmail upon form submission, how should I handle a formatting error for a blank cell?

Simple call logger/lead sheet generator using Google Forms and a script to send out the lead upon submission. I'm getting a format error when the user does not input a date into the field. I don't want to require an appt. time/date in the form. Here is my code:
function sendEmails() {
//gets list of
var leadss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("LatestLeadSheet");
var leadList = leadss.getRange(3, 1, leadss.getLastRow() - 2, leadss.getLastColumn()).getValues();
var timeZone = Session.getScriptTimeZone();
var today = Utilities.formatDate(new Date(), timeZone, "MM/dd/yyyy"); //Today's date for email subject line
var fullMessage = ""; //clears fullMessage variable
// Creates body of email. Looping through each array from LatestLeadSheet tab
for (var j = 0; j < leadList.length; j++) {
var message = "Client Name: " + leadList[j][1] + "\n" +
"Client Phone: " + leadList[j][3] + "\n" +
"Client Email: " + leadList[j][8] + "\n" +
"Interested in: " + leadList[j][5] + "\n" +
"Quoted rate of: " + leadList[j][6] + "\n" +
"Notes: " + leadList[j][7] + "\n" +
"Appointment Set for: " + Utilities.formatDate(leadList[j][10], timeZone, "HH:mm MM/dd/yyyy") + "\n"
//+"At: "+Utilities.formatDate(leadList[j][11],timeZone,"h:mm a") + "\n\n"
+
"Referral Source: " + leadList[j][2] + "\n" +
"Other Info: " + leadList[j][4] + "\n" +
"Documents were sent (Y/N): " + leadList[j][9] + "\n" +
"Call was taken at: " + Utilities.formatDate(leadList[j][0], timeZone, "HH:mm MM/dd/yyyy") + "\n" +
"Call was logged by: " + leadList[j][12] + "\n\n\n\n";
var fullMessage = fullMessage + message;
}
//Sends email to each recipient listed on SalesTeam tab
var subject = "DMS Call Sheet from: " + today;
var emailss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SalesTeam");
var lr = emailss.getLastRow();
for (var i = 2; i <= lr; i++) {
var currentEmail = emailss.getRange(i, 2).getValue();
MailApp.sendEmail(currentEmail, subject, "Please follow up with the following potential clients: \n\n" + fullMessage)
}
}

how do i get a new number to generate

i need to make a dice rolling program that rolls dice and says who won if it is a tie it rolls again and after each win you earn a point first to 5 wins the game whenever i run mine it uses the same numbers over and over again because it only generated the once how can i fix this and what else do i need to do after this issue to finish the program, thanks for the help!
<script>
var comp1 = Math.floor((Math.random()*6) + 1);
var comp2 = Math.floor((Math.random()*6) + 1);
var you1 = Math.floor((Math.random()*6) + 1);
var you2 = Math.floor((Math.random()*6) + 1);
var counter = 1;
var youPoints = 0;
var mePoints = 0;
while(counter < 6)
{{
alert("Let's shake some dice!")
alert("your turn to roll \n\n you shook a " + you1 + " and a " + you2 + ", so you have " + (you1 + you2));
alert("my turn to roll \n\n I shook a " + comp1 + " and a " + comp2 + ", so I have " + (comp1 + comp2));
counter++
var you = you1 + you2;
var me = comp1 + comp2;
if(you > me)
{
alert("you win " + you + " to " + me);
youPoints++
}
if (me > you)
{
alert("I win " + me + " to " + you);
mePoints++
}
}}
</script>
You're initializing your random variables (you1, you2) outside the while loop.
It's being initialized only once and hence producing the same number every time.
Bring it inside the loop, and that might fix it!
Move the code the generates the random numbers to inside of the loop because, right now, they only generate once... before the loop even starts.
Also, do yourself a favor and use a for counting loop, rather than a while, because while loops are easily misconfigured to cause infinite loops to occur.
var youPoints = 0;
var mePoints = 0;
for(var counter = 1; counter < 6; counter++){
// The code that generates the random numbers has to be in the loop
// in order for new randoms to be generated upon each loop iteration
var comp1 = Math.floor((Math.random()*6) + 1);
var comp2 = Math.floor((Math.random()*6) + 1);
var you1 = Math.floor((Math.random()*6) + 1);
var you2 = Math.floor((Math.random()*6) + 1);
alert("Let's shake some dice!")
alert("your turn to roll \n\n you shook a " + you1 + " and a " + you2 + ", so you have " + (you1 + you2));
alert("my turn to roll \n\n I shook a " + comp1 + " and a " + comp2 + ", so I have " + (comp1 + comp2));
var you = you1 + you2;
var me = comp1 + comp2;
// Don't make two separate if statements. Use one with an else if
if(you > me) {
alert("you win " + you + " to " + me);
youPoints++
} else if (me > you) {
alert("I win " + me + " to " + you);
mePoints++
}
}
Here you go, this should be a complete working example.
Note: I replaced alert() for console.log() so we can see the output here in the console and without popups, but it will work either way.
var compPoints = 0;
var youPoints = 0;
var winnerOfFive = false;
function rollTheDice() {
return Math.floor((Math.random()*6) + 1);
}
function rollAllDice() {
let you1 = rollTheDice();
let you2 = rollTheDice();
let comp1 = rollTheDice();
let comp2 = rollTheDice();
console.log("your turn to roll \n\n you shook a " + you1 + " and a " + you2 + ", so you have " + (you1 + you2));
console.log("my turn to roll \n\n I shook a " + comp1 + " and a " + comp2 + ", so I have " + (comp1 + comp2));
var you = you1 + you2;
var me = comp1 + comp2;
if(you > me) {
console.log("you win " + you + " to " + me);
youPoints++;
} else if(me > you) {
console.log("I win " + me + " to " + you);
compPoints++;
} else {
console.log("It was a tie, no one wins. Re-rolling...");
rollAllDice();
}
}
function startGame() {
while( !winnerOfFive ) {
console.log("Let's shake some dice!")
rollAllDice();
if(compPoints == 5) {
console.log("Comp is first to 5 games and wins " + compPoints + " to " + youPoints);
winnerOfFive = true;
} else if (youPoints == 5) {
console.log("You are first to 5 games and win " + youPoints + " to " + compPoints);
winnerOfFive = true;
}
}
}
// Start the game like this
startGame();

SQL node.js Syntax error on what seems to be a valid query?

I'm running an update on a table to set a position. I've extracted the query and manually run it on my database and works fine but when passed through connection.query() it seems to think there's a syntax error in my node.js console.
function sendShipPosition(position) {
var input = '';
if (position.moving === true) {
var currentdate = new Date();
var datetime = currentdate.getFullYear() + "-"
+ (currentdate.getMonth()+1) + "-"
+ currentdate.getDate() + " "
+ currentdate.getHours() + ":"
+ currentdate.getMinutes() + ":"
+ currentdate.getSeconds();
var input = ', moving_datetime = ' + datetime;
}
connection.query('UPDATE ships SET x_axis = :x, y_axis = :y' + input + ' WHERE ship_id = :ship_id'), {
x: parseInt(position.x),
y: parseInt(position.y),
ship_id: 1
};
}
Here is the syntax error:
Here's the input data value of 'position' variable:
{ x: '-605', y: '-257', moving: 0 }
I hope I'm not being too much of a dunce and sorry for the low quality question.
Thanks
This function will generate SQL code which is missing quotes around the datetime variable, resulting in invalid SQL code.
function sendShipPosition(position) {
var input = '';
if (position.moving === true) {
var currentdate = new Date();
var datetime = currentdate.getFullYear() + "-"
+ (currentdate.getMonth()+1) + "-"
+ currentdate.getDate() + " "
+ currentdate.getHours() + ":"
+ currentdate.getMinutes() + ":"
+ currentdate.getSeconds();
# Here!
var input = ', moving_datetime = \'' + datetime + '\''
}
connection.query('UPDATE ships SET x_axis = :x, y_axis = :y' + input + ' WHERE ship_id = :ship_id'), {
x: parseInt(position.x),
y: parseInt(position.y),
ship_id: 1
};
}

Get a Google Sheet script to skip empty rows?

I have a script that sends e-mails from a google sheet. The data in the sheet is populated with a google form. A few fields in the sheet use array formulas to add additional data to the sheet example: array formulas in the sheet to populate fields:
=ArrayFormula(IF(ROW(A:A)=1,"link",VLOOKUP($C:C,array!$A$2:$C$9000,3,FALSE)))
This causes "#N/A" to show in rows where no user has submitted data. I am ok with that but it is causing the script to take a long time to run. When the user submits data, a timestamp is placed in the first column. Can I use that to get the script to skip to stop if empty? Right now, I have the script checking 1000 rows but ideally it would check rows for timestamp and if no timestamp, stop.
/**
* Add a menu item that calls this script
*/
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menu = [{
name: "Send Email",
functionName: "uiSendEmail"
}];
ss.addMenu("SCCCounseling", menu);
}
var EMAIL_SENT = "EMAIL_SENT";
/**
* Send the e-mail to everyone listed in the spreadsheet
*/
function uiSendEmail() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 1000;
var dataRange = sheet.getRange(startRow, 1, numRows, 1000)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var timestamp = row[0];
var username = row[1];
var counselor = row[2];
var date = row[3];
var sName = row[4];
var wNum = row[5];
var toemail = row[6];
var sLName= row[7];
var pin = row[8];
var link = row[9];
var cMail = row[10];
var emailSent = row[11];
var subject = "Online Counseling Appointment Confirmation - " + sName + " " + sLName + " " + wNum + " ";
var emailBody = "Online Counseling Appointment " + " - " + sName + " " + sLName + " " + wNum +
"\n\nHello " + sName +
"\n\n\nYou are scheduled for an online counseling appointment for Sacramento City College: " +
"\n\n\nDate: " + date +
"\n\nPlease follow the instructions below at least one day before your appointment to make " +
"\nsure that your computer is ready. " +
"\n\nIf your computer is not ready, you will not be able to " +
"\nparticipate in online counseling. " +
"\n\nTo cancel your appointment, please email: " +
"\n\nCounselor: " + counselor + " at " + cMail +
"\n\nYou will be required to show photo identification at the start of the appointment to verify " +
"\nyour identity. " +
"\n\n\nONE DAY BEFORE YOUR APPOINTMENT " +
"\n\nGo to the following link to test your computer readiness one day before your " +
"\nscheduled online counseling appointment: " +
"\n\nhttp://www.cccconfer.org/support/supportReadiness.aspx " +
"\n\n\nFIVE MINUTES BEFORE YOUR APPOINTMENT: " +
"\n\nGo to the following link to connect to the online counseling appointment and the " +
"\ncounselor will join you: " + link +
"\n\n\nIf you want to use the phone for audio: " +
"\n\nTelephone Conference Line: 719-785-4469, Toll-free: 1-888-450-4821 " +
"\n\nStudent PIN: " + pin +
"\n\n\nFOR ASSISTANCE CONNECTING" +
"\n\nContact CCC Confer Client Services, Monday - Friday 8am - 4pm " +
"\n\nPhone: 1-760-744-1150 ext 1537 or 1554 " +
"\n\nEmail: clientservices#cccconfer.org " +
"\n\n\nThank you " + sName;
var htmlBody = "<b>Online Counseling Appointment Confirmation" + " -</b> " + " - " + sName + " " + sLName + " " + wNum +
"<br/><br/><br/>" + "Hello " + sName + ", <br/><br/>" + "You are scheduled for an online counseling appointment for Sacramento City College: <i>" +
"<br/><br/><br/>" + "<b>Date: " + date + "<br/><br/>" + "</b><br/>" + "</i><br/>Please follow the instructions below <b>at least one day before</b> your appointment to make sure that your computer is ready." +
"<br/><br/><i>If your computer is not ready, you will not be able to participate in online counseling.</i> " + "<br/><br/> To cancel your appointment, please email: " +
"<br/><br/><font color=\"red\">Counselor:</font> " + counselor + " at " + cMail + "<br/><br/><br/>You will be required to show photo identification at the start of the appointment to verify your identity. " +
"<br/><br/><br/><b>ONE DAY BEFORE YOUR APPOINTMENT:</b> " + "<br/><br/>➢ Go to the following link to test your computer readiness one day before your scheduled online counseling appointment: " +
"<br/><br/>http://www.cccconfer.org/support/supportReadiness.aspx " +
"<br/><br/><br/><b>FIVE MINUTES BEFORE YOUR APPOINTMENT:</b>" +
"<br/><br/>➢ Go to the following link to connect to the online counseling appointment and the counselor will join you (link to counselor online room). " +
"<br/><br/> " + link +
"<br/><br/>➢ If you want to use the phone for audio: " +
"<br/><ul><li>Telephone Conference Line: 719-785-4469, Toll-free: 1-888-450-4821</li><li>Student PIN: " + pin + "</li></ul>" +
"<br/><br/><br/><b>FOR ASSISTANCE CONNECTING</b>" +
"<br/><br/>Contact CCC Confer Client Services, Monday - Friday 8am - 4pm " +
"<br/><br/>Phone: 1-760-744-1150 ext 1537 or 1554 " +
"<br/><br/>Email: clientservices#cccconfer.org " +
"<br/><br/><br/>Thank You! " + sName;
var optAdvancedArgs = {name: "SCC Counseling", htmlBody: htmlBody};
if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
var subject = "Online Counseling Appointment Confirmation - " + sName + " " + wNum + " ";
MailApp.sendEmail(toemail, subject, emailBody, optAdvancedArgs);
sheet.getRange(startRow + i, 12).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}
Create a simple function to test for #NA!:
function checkForNa() {
var theVal = SpreadsheetApp.getActiveSpreadsheet().getRange("A1").getValue();
if (theVal === "#NA!") {
Logger.log('it's NA');
return;
};
Logger.log('There is data. The code continued');
};
Intentionally cause an #NA! error, and run the code.
If the code works, incorporate the conditional check into your code. The return; statement will stop your code.
If you don't want your code to stop, but to skip this row, a break; statement can be used, but the break; can only be used inside of a loop. So, you'll need a nested loop to check for the #NA! value, to skip over that one line.
function checkForNa() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 1000;
var dataRange = sheet.getRange(startRow, 2, numRows, 1000)
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var theVal = data[i][0]; //Get first value out of this row
for (var j = 0;j<1;j++) { //Only loops once
if (theVal === "#NA!") {
Logger.log('skipped this row: ' + i);
break;
};
Logger.log('loop number: ' + i);
};
};
};
This is example code. You'll need to adapt it to your code.
Just create a simple IF statement to check for a timestamp. It will work just fine. You may have to fix closing brackets because I'm not sure where they were supposed to be.
/**
* Add a menu item that calls this script
*/
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menu = [{
name: "Send Email",
functionName: "uiSendEmail"
}];
ss.addMenu("SCCCounseling", menu);
}
var EMAIL_SENT = "EMAIL_SENT";
/**
* Send the e-mail to everyone listed in the spreadsheet
*/
function uiSendEmail() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 1000;
var dataRange = sheet.getRange(startRow, 1, numRows, 1000)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
if (data[i][INDEX_OF_TIMESTAMP] != "") {
var row = data[i];
var timestamp = row[0];
var username = row[1];
var counselor = row[2];
var date = row[3];
var sName = row[4];
var wNum = row[5];
var toemail = row[6];
var sLName= row[7];
var pin = row[8];
var link = row[9];
var cMail = row[10];
var emailSent = row[11];
var subject = "Online Counseling Appointment Confirmation - " + sName + " " + sLName + " " + wNum + " ";
var emailBody = "Online Counseling Appointment " + " - " + sName + " " + sLName + " " + wNum +
"\n\nHello " + sName +
"\n\n\nYou are scheduled for an online counseling appointment for Sacramento City College: " +
"\n\n\nDate: " + date +
"\n\nPlease follow the instructions below at least one day before your appointment to make " +
"\nsure that your computer is ready. " +
"\n\nIf your computer is not ready, you will not be able to " +
"\nparticipate in online counseling. " +
"\n\nTo cancel your appointment, please email: " +
"\n\nCounselor: " + counselor + " at " + cMail +
"\n\nYou will be required to show photo identification at the start of the appointment to verify " +
"\nyour identity. " +
"\n\n\nONE DAY BEFORE YOUR APPOINTMENT " +
"\n\nGo to the following link to test your computer readiness one day before your " +
"\nscheduled online counseling appointment: " +
"\n\nhttp://www.cccconfer.org/support/supportReadiness.aspx " +
"\n\n\nFIVE MINUTES BEFORE YOUR APPOINTMENT: " +
"\n\nGo to the following link to connect to the online counseling appointment and the " +
"\ncounselor will join you: " + link +
"\n\n\nIf you want to use the phone for audio: " +
"\n\nTelephone Conference Line: 719-785-4469, Toll-free: 1-888-450-4821 " +
"\n\nStudent PIN: " + pin +
"\n\n\nFOR ASSISTANCE CONNECTING" +
"\n\nContact CCC Confer Client Services, Monday - Friday 8am - 4pm " +
"\n\nPhone: 1-760-744-1150 ext 1537 or 1554 " +
"\n\nEmail: clientservices#cccconfer.org " +
"\n\n\nThank you " + sName;
var htmlBody = "<b>Online Counseling Appointment Confirmation" + " -</b> " + " - " + sName + " " + sLName + " " + wNum +
"<br/><br/><br/>" + "Hello " + sName + ", <br/><br/>" + "You are scheduled for an online counseling appointment for Sacramento City College: <i>" +
"<br/><br/><br/>" + "<b>Date: " + date + "<br/><br/>" + "</b><br/>" + "</i><br/>Please follow the instructions below <b>at least one day before</b> your appointment to make sure that your computer is ready." +
"<br/><br/><i>If your computer is not ready, you will not be able to participate in online counseling.</i> " + "<br/><br/> To cancel your appointment, please email: " +
"<br/><br/><font color=\"red\">Counselor:</font> " + counselor + " at " + cMail + "<br/><br/><br/>You will be required to show photo identification at the start of the appointment to verify your identity. " +
"<br/><br/><br/><b>ONE DAY BEFORE YOUR APPOINTMENT:</b> " + "<br/><br/>➢ Go to the following link to test your computer readiness one day before your scheduled online counseling appointment: " +
"<br/><br/>http://www.cccconfer.org/support/supportReadiness.aspx " +
"<br/><br/><br/><b>FIVE MINUTES BEFORE YOUR APPOINTMENT:</b>" +
"<br/><br/>➢ Go to the following link to connect to the online counseling appointment and the counselor will join you (link to counselor online room). " +
"<br/><br/> " + link +
"<br/><br/>➢ If you want to use the phone for audio: " +
"<br/><ul><li>Telephone Conference Line: 719-785-4469, Toll-free: 1-888-450-4821</li><li>Student PIN: " + pin + "</li></ul>" +
"<br/><br/><br/><b>FOR ASSISTANCE CONNECTING</b>" +
"<br/><br/>Contact CCC Confer Client Services, Monday - Friday 8am - 4pm " +
"<br/><br/>Phone: 1-760-744-1150 ext 1537 or 1554 " +
"<br/><br/>Email: clientservices#cccconfer.org " +
"<br/><br/><br/>Thank You! " + sName;
var optAdvancedArgs = {name: "SCC Counseling", htmlBody: htmlBody};
if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
var subject = "Online Counseling Appointment Confirmation - " + sName + " " + wNum + " ";
MailApp.sendEmail(toemail, subject, emailBody, optAdvancedArgs);
sheet.getRange(startRow + i, 12).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}
If you know how many rows are usually empty (em), check those rows with r+(em+1). In the example below, I am dealing with:
1 row missing randomly
New rows populated, but column A missing
New rows populated with column A populated
I checked for all 3 conditions in a while loop.
function onRow(e){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var column = ss.getRange('A:I');
var values = column.getValues(); // get all data in one call
var r = 0;
while ( (values[r] && values[r][1] != "") || (values[r] && values[r][2] != "" ) || (values[r+2] && values[r+2][2] != "" )) {
r++;
}

Categories