Checkbox to approve entry on Google sheets and trigger an approval email - google-apps-script

Currently im having a prompt window popup that collects the S. No of the entry and then approves that entry and sends out an approval email. Instead of this, i wanna have a check box that one checks to approve the entry and a function is triggered
function function1() {
var sheet= SpreadsheetApp.openById("xxxx").getSheetByName("payments");
var ui = SpreadsheetApp.getUi();
var result = ui.prompt('Please enter the S. No of the entry you want to approve', ui.ButtonSet.OK_CANCEL);
var button = result.getSelectedButton();
var sno = result.getResponseText();
for (var i=1; i<=100 ; i++)
{
Logger.log(sheet.getRange(i,1).getValue());
if(sno == sheet.getRange(i,1).getValue())
{
var index = i;
}
}
Logger.log(index);
var invitem = sheet.getRange(index,5).getValue();
var invdesc = sheet.getRange(index,6).getValue();
var reqby = sheet.getRange(index,3).getValue();
var amount = sheet.getRange(index,8).getValue();
if (button == ui.Button.OK)
{
var subject = 'Payment release request approved';
var body = '<p>Hello</p> <p>This particular payment release is approved from my end</p> <p>Invoice Item: '+ invitem +'</p> <p>Description: '+ invdesc +'</p> <p>Requested By: '+reqby+' </p> <p>Requested By: '+amount+' </p> <p> </p> <p><em>This is an automated email triggerred post approval</em></p>'
var email= 'finance#xxxx.xxx';
GmailApp.sendEmail(email, subject, "Requires HTML", {
htmlBody: body})
sheet.getRange(index,16).setValue("Approved").setBackground('#008000');
}
}

Okay here's a function and an installable trigger create function
function onMyEdit(e) {
const sh = e.range.getSheet();
if(sh.getName() == 'Your sheet name' && e.range.columnStart == '15' && e.value == "TRUE") {
let snum = sh.getRange(e.range.rowStart,1).getValue();
ApproveAndSendEmail({snum:snum});
}
}
function createTrigger() {
const ss = SpreadsheetApp.getActive();
if(ScriptApp.getProjectTriggers().filter(t => t.getHandlerFunction() == "onMyEdit").length == 0) {
ScriptApp.newTrigger('onMyEdit').forSpreadsheet(ss).onEdit().create();
}
}

Related

Google App Script to trigger on cell value change with email notification

looking for a help to fix my script in Google spreadsheets.
I want to build a function that sends an email every time a certain cell in the list is updated.
Here is my code, but it doesn't work.
Looking for your help to find and fix my issue
function onEdit(e) {
const specificSheet = "Inventory"
const specificCell = "B1"
let sheetCheck = (e.range.getSheet().getName() == specificSheet)
let cellCheck = (e.range.getA1Notation() == specificCell)
if (!(sheetCheck && cellCheck)) {
return
}
else {
sendEmail(){
var subject = "New update";
var emailAddress = "example#gmail.com";
var message = "new update: link";
MailApp.sendEmail(emailAddress, subject, message)
}
}
}
Send email on an Edit
function onMyEdit(e) {
const sh = e.range.getSheet();
if (sh.getName() = "Inventory" && e.range.columnStart == 2 && e.range.rowStart == 1) {
var subject = "New update";
var emailAddress = "example#gmail.com";
var message = "new update: link";
MailApp.sendEmail(emailAddress, subject, message)
}
}
I think this needs to be an installable trigger in order to send an email.
Sometimes Sheet can not process complex operations related to onEdit(e), so maybe this could help:
function onEdit(e) {
const specificSheet = "Inventory";
const specificCell = "B1";
var range = e.range;
var ss = e.source;
var sheetName = ss.getActiveSheet().getName();
var a1Notation = range.getA1Notation();
if ((sheetName==specificSheet) && (a1Notation==specificCell)) {
var props = PropertiesService.getScriptProperties();
props.setProperty("CHECKED","TRUE");
}
}
function sendEmail(){
var subject = "New update";
var emailAddress = "example#gmail.com";
var message = "new update: link";
var props = PropertiesService.getScriptProperties();
var checked = props.getProperty("CHECKED");
if (checked == "TRUE"){
GmailApp.sendEmail(emailAddress, subject, message);
Utilities.sleep(3000);
props.setProperty("CHECKED","FALSE");
}
}
Another thing you should do is setting sendEmail() function is activated by time trigger every minute or so...

Collecting a Gmail Username when a Button is Pressed In Google Sheets

I am creating a bathroom sign out sheet for my middle school students. I have created a Google App Script that Collects students names from a dropdown box and then logs the date and time. Everything seems to work great except when 500 students have access to the sheet at the same time. If a student selects their name it can possibly change before the script can be run. I would like to replace the dropdown box with a script that will automatically grab their Google User Name. Is there anyway this can be done? I am a novice programmer and tend to get things to work by tinkering around with it, but this seems to be above my head. Here is the Google Sheet and the Script is attached as well. Thanks in advance
https://docs.google.com/spreadsheets/d/e/2PACX-1vR36FnMTbJV4Nl8X8x_VyG107Y8Q-oCSgfG3ITEvaMjSraMv-bUH2u4FuWSE74Qg1gCrO5bg12pvawe/pubhtml
function clockIn()
{
//DEFINE ALL ACTIVE SHEETS
var ss = SpreadsheetApp.getActiveSpreadsheet();
//DEFINE MAIN SHEET
var mainSheet = ss.getSheetByName("DATASHEET");
//LAST ROW ON MAIN SHEET
var lastRow = mainSheet.getLastRow();
for (var j = 5; j <= lastRow; j++)
{
// CHECK CLOCK IN
if(mainSheet.getRange('B1:B1').getValue() == mainSheet.getRange(j, 1).getValue() && mainSheet.getRange(j,3).getValue() == '')
{
Browser.msgBox("⚠️ You are Already Signed Out","Please Click the Returning to Classroom Button and then Try Again!",Browser.Buttons.OK);
return;
}
}
//_________________________________________________________________________________________________________________________________________________//
// ADD CLOCK IN RECORD
mainSheet.getRange(lastRow+1,1).setValue(mainSheet.getRange('B1:B1').getValue()).setFontSize(12);
mainSheet.getRange(lastRow+1,2).setValue(new Date()).setNumberFormat("MM/dd/yyyy hh:mm:ss A/P").setHorizontalAlignment("left").setFontSize(12);
//CLEARCONTENTS
{
var sheet = ss.getSheetByName("MAIN");
sheet.getRange('B1:B2').clearContent();
}
if (mainSheet.getRange('B1:B1').getValue() == mainSheet.getRange('B1:B1').getValue() && mainSheet.getRange(j,3).getValue() == '')
{
SpreadsheetApp.getUi().alert("⏰ Please Hurry Back! ⏰","Your Teacher is Waiting",SpreadsheetApp.getUi().ButtonSet.OK);
}
}
//_________________________________________________________________________________________________________________________________________________//
function clockOut() {
//DEFINE ALL ACTIVE SHEETS
var ss = SpreadsheetApp.getActiveSpreadsheet();
//DEFINE MAIN SHEET
var mainSheet = ss.getSheetByName("DATASHEET");
//LAST ROW ON MAIN SHEET
var lastRow = mainSheet.getLastRow();
var foundRecord = false;
for (var j = 5; j <= lastRow; j++)
{
// FIND CLOCK IN RECORD
if(mainSheet.getRange('B1:B1').getValue() == mainSheet.getRange(j, 1).getValue() && mainSheet.getRange(j,3).getValue() == '')
{
SpreadsheetApp.getUi().alert("🙏 Thank You! 🙏"," " ,SpreadsheetApp.getUi().ButtonSet.OK);
// UPDATE CLOCK IN RECORD
mainSheet.getRange(j,3).setValue(new Date()).setNumberFormat("MM/dd/yyyy hh:mm:ss A/P").setHorizontalAlignment("left").setFontSize(12);
var totalTime = (mainSheet.getRange(j,3).getValue() - mainSheet.getRange(j,2).getValue()) /(60*100*1000);
mainSheet.getRange(j,4).setValue(totalTime.toFixed(2)).setNumberFormat("#0.00").setHorizontalAlignment("left").setFontSize(12);
foundRecord = true;
}
}
//CLEARCONTENTS
{
var sheet = ss.getSheetByName("MAIN");
sheet.getRange('B1:B2').clearContent();
}
// IF NO CLOCK IN RECORD
if(foundRecord == false)
{
SpreadsheetApp.getUi().alert("⚠️ No Record ⚠️","You Might Have Forget to Sign Out?" ,SpreadsheetApp.getUi(). ButtonSet.OK);
}
}
//_________________________________________________________________________________________________________________________________________________//
// CALL TOTAL HOURS
TotalHours();
function TotalHours()
{
//DEFINE ALL ACTIVE SHEETS
var ss = SpreadsheetApp.getActiveSpreadsheet();
//DEFINE MAIN SHEET
var mainSheet = ss.getSheetByName("DATASHEET");
//LAST ROW ON MAIN SHEET
var lastRow = mainSheet.getLastRow();
//DEFINE ARRAY
var totals = [];
//LOOP THROUGH ALL RATES
for (var j = 5; j <= lastRow; j++)
{
var rate = mainSheet.getRange(j, 4).getValue();
var name = mainSheet.getRange(j, 1).getValue();
var foundRecord = false;
for(var i = 0; i < totals.length; i++)
{
//FOUND RECORD ADD TO TOTAL
if(name == totals[i][0] && rate != '')
{
totals[i][1] = totals[i][1] + rate;
foundRecord = true;
}
}
//ADD NEW RECORD, EXISTING RECORD NOT FOUND
if(foundRecord == false && rate != '')
{
totals.push([name, rate]);
}
}
//CLEAR DATA
mainSheet.getRange("F5:G1000").clear();
//DISPLAY TOTALS
for(var i = 0; i < totals.length; i++)
{
mainSheet.getRange(5+i,6).setValue(totals[i][0]).setFontSize(12);
mainSheet.getRange(5+i,7).setValue(totals[i][1]).setFontSize(12);
}
}
//_________________________________________________________________________________________________________________________________________________//
function ClearCells()
{
var sheet = SpreadsheetApp.getActive().getSheetByName('DATASHEET');
sheet.getRange('A5:G1000').clearContent();
}
//_________________________________________________________________________________________________________________________________________________//
function clearRange()
{
// replace 'Sheet1' with your actual sheet name
// replace 'dhrhrejYOURSHETIDerhe5j54j5j' with your actual sheet ID
var sheetActive = SpreadsheetApp.openById("1sjx0UAv73wiW-Jo1e8QWZuanjKK2tsjveVXjB1y_IHw").getSheetByName("DATASHEET");
sheetActive.getRange('A5:G1000').clearContent();
}
//_________________________________________________________________________________________________________________________________________________//
``
This works for me:
function getUserEmail() {
SpreadsheetApp.getActive().toast(Session.getActiveUser().getEmail());
}
But it may not work all of the time because of a complex set of security protocols which I know nothing about.
Since you are pertaining to the email address of the user, you can use Session.getActiveUser() which will give you the current user, then use getEmail() to get the current user's email address. Similar to what #Cooper suggested
You just need to use them in your clockIn() and clockOut():
function clockIn()
{
//DEFINE ALL ACTIVE SHEETS
var ss = SpreadsheetApp.getActiveSpreadsheet();
//DEFINE MAIN SHEET
var mainSheet = ss.getSheetByName("DATASHEET");
//LAST ROW ON MAIN SHEET
var lastRow = mainSheet.getLastRow();
for (var j = 5; j <= lastRow; j++)
{
// CHECK CLOCK IN
if(Session.getActiveUser().getEmail() == mainSheet.getRange(j, 1).getValue() && mainSheet.getRange(j,3).getValue() == '')
{
Browser.msgBox("⚠️ You are Already Signed Out","Please Click the Returning to Classroom Button and then Try Again!",Browser.Buttons.OK);
return;
}
}
//_________________________________________________________________________________________________________________________________________________//
// ADD CLOCK IN RECORD
mainSheet.getRange(lastRow+1,1).setValue(Session.getActiveUser().getEmail()).setFontSize(12);
mainSheet.getRange(lastRow+1,2).setValue(new Date()).setNumberFormat("MM/dd/yyyy hh:mm:ss A/P").setHorizontalAlignment("left").setFontSize(12);
//CLEARCONTENTS
{
var sheet = ss.getSheetByName("MAIN");
sheet.getRange('B1:B2').clearContent();
}
if (Session.getActiveUser().getEmail() == Session.getActiveUser().getEmail() && mainSheet.getRange(j,3).getValue() == '')
{
SpreadsheetApp.getUi().alert("⏰ Please Hurry Back! ⏰","Your Teacher is Waiting",SpreadsheetApp.getUi().ButtonSet.OK);
}
}
//_________________________________________________________________________________________________________________________________________________//
function clockOut() {
//DEFINE ALL ACTIVE SHEETS
var ss = SpreadsheetApp.getActiveSpreadsheet();
//DEFINE MAIN SHEET
var mainSheet = ss.getSheetByName("DATASHEET");
//LAST ROW ON MAIN SHEET
var lastRow = mainSheet.getLastRow();
var foundRecord = false;
for (var j = 5; j <= lastRow; j++)
{
// FIND CLOCK IN RECORD
if(Session.getActiveUser().getEmail() == mainSheet.getRange(j, 1).getValue() && mainSheet.getRange(j,3).getValue() == '')
{
SpreadsheetApp.getUi().alert("🙏 Thank You! 🙏"," " ,SpreadsheetApp.getUi().ButtonSet.OK);
// UPDATE CLOCK IN RECORD
mainSheet.getRange(j,3).setValue(new Date()).setNumberFormat("MM/dd/yyyy hh:mm:ss A/P").setHorizontalAlignment("left").setFontSize(12);
var totalTime = (mainSheet.getRange(j,3).getValue() - mainSheet.getRange(j,2).getValue()) /(60*100*1000);
mainSheet.getRange(j,4).setValue(totalTime.toFixed(2)).setNumberFormat("#0.00").setHorizontalAlignment("left").setFontSize(12);
foundRecord = true;
}
}
//CLEARCONTENTS
{
var sheet = ss.getSheetByName("MAIN");
sheet.getRange('B1:B2').clearContent();
}
// IF NO CLOCK IN RECORD
if(foundRecord == false)
{
SpreadsheetApp.getUi().alert("⚠️ No Record ⚠️","You Might Have Forget to Sign Out?" ,SpreadsheetApp.getUi(). ButtonSet.OK);
}
}
//_____
Another option is to use promt dialog to ask user to input their name when clockIn() or clockOut() was called. Then change the inputted name to capital letters.
Your Code:
function clockIn()
{
//DEFINE ALL ACTIVE SHEETS
var ss = SpreadsheetApp.getActiveSpreadsheet();
//DEFINE MAIN SHEET
var mainSheet = ss.getSheetByName("DATASHEET");
//LAST ROW ON MAIN SHEET
var lastRow = mainSheet.getLastRow();
var ui = SpreadsheetApp.getUi();
var response = ui.prompt('Enter your name:',ui.ButtonSet.OK_CANCEL);
var studentName;
// Process the user's response.
if (response.getSelectedButton() == ui.Button.OK) {
Logger.log('The user\'s name is %s.', response.getResponseText());
studentName = studentName.toUpperCase();
studentName = response.getResponseText();
} else {
Logger.log('Request was cancelled.');
return;
}
for (var j = 5; j <= lastRow; j++)
{
// CHECK CLOCK IN
if(studentName == mainSheet.getRange(j, 1).getValue() && mainSheet.getRange(j,3).getValue() == '')
{
Browser.msgBox("⚠️ You are Already Signed Out","Please Click the Returning to Classroom Button and then Try Again!",Browser.Buttons.OK);
return;
}
}
//_________________________________________________________________________________________________________________________________________________//
// ADD CLOCK IN RECORD
mainSheet.getRange(lastRow+1,1).setValue(studentName).setFontSize(12);
mainSheet.getRange(lastRow+1,2).setValue(new Date()).setNumberFormat("MM/dd/yyyy hh:mm:ss A/P").setHorizontalAlignment("left").setFontSize(12);
//CLEARCONTENTS
{
var sheet = ss.getSheetByName("MAIN");
sheet.getRange('B1:B2').clearContent();
}
if (studentName == studentName && mainSheet.getRange(j,3).getValue() == '')
{
SpreadsheetApp.getUi().alert("⏰ Please Hurry Back! ⏰","Your Teacher is Waiting",SpreadsheetApp.getUi().ButtonSet.OK);
}
}
//_________________________________________________________________________________________________________________________________________________//
function clockOut() {
//DEFINE ALL ACTIVE SHEETS
var ss = SpreadsheetApp.getActiveSpreadsheet();
//DEFINE MAIN SHEET
var mainSheet = ss.getSheetByName("DATASHEET");
//LAST ROW ON MAIN SHEET
var lastRow = mainSheet.getLastRow();
var foundRecord = false;
var ui = SpreadsheetApp.getUi();
var response = ui.prompt('Enter your name:',ui.ButtonSet.OK_CANCEL);
var studentName;
// Process the user's response.
if (response.getSelectedButton() == ui.Button.OK) {
Logger.log('The user\'s name is %s.', response.getResponseText());
studentName = response.getResponseText();
studentName = studentName.toUpperCase();
} else {
Logger.log('Request was cancelled.');
return;
}
for (var j = 5; j <= lastRow; j++)
{
// FIND CLOCK IN RECORD
if(studentName == mainSheet.getRange(j, 1).getValue() && mainSheet.getRange(j,3).getValue() == '')
{
SpreadsheetApp.getUi().alert("🙏 Thank You! 🙏"," " ,SpreadsheetApp.getUi().ButtonSet.OK);
// UPDATE CLOCK IN RECORD
mainSheet.getRange(j,3).setValue(new Date()).setNumberFormat("MM/dd/yyyy hh:mm:ss A/P").setHorizontalAlignment("left").setFontSize(12);
var totalTime = (mainSheet.getRange(j,3).getValue() - mainSheet.getRange(j,2).getValue()) /(60*100*1000);
mainSheet.getRange(j,4).setValue(totalTime.toFixed(2)).setNumberFormat("#0.00").setHorizontalAlignment("left").setFontSize(12);
foundRecord = true;
}
}
//CLEARCONTENTS
{
var sheet = ss.getSheetByName("MAIN");
sheet.getRange('B1:B2').clearContent();
}
// IF NO CLOCK IN RECORD
if(foundRecord == false)
{
SpreadsheetApp.getUi().alert("⚠️ No Record ⚠️","You Might Have Forget to Sign Out?" ,SpreadsheetApp.getUi(). ButtonSet.OK);
}
}
//_____

How do I call a mailApp function within an onEdit function?

I have an onEdit function where if executed should send an email. However, some research has turned up that the mailApp functions don't work with onEdit. I'm currently toying around with workarounds but wondering if others have solutions they've come up with.
function onEdit(e) {
var sheet = e.source.getActiveSheet();
var sheetName = sheet.getName();
//if editing specific sheet
if (sheetName == "draft_test" ) {
//if editing 6th column
var r = e.source.getActiveRange();
if (r.getColumn() == 6 ) {
var player = sheet.getActiveCell().getValue();
// Display a dialog box with a message and "Yes" and "No" buttons.
var ui = SpreadsheetApp.getUi();
var response = ui.alert('Do you want to draft '+player+'?', ui.ButtonSet.YES_NO);
// Process the user's response.
if (response == ui.Button.YES) {
//***********FOR SOME REASON EXECUTING THIS FUNCTION ISNT WORKING******************
emailLeague();
//sortAutoRoster();
} else {
}
}
}
}
function emailLeague() {
var draftSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("draft_test");
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("test_email");
var emailSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Manager Info");
//actual email address omitted
var recipient = 'emailaddress#gmail.com';
//get array of all picks on "draft test" tab, and find latest one
var picks = draftSheet.getRange(3,6,146,1).getValues();
for (var i=0; i<picks.length; i++){
if (picks[i] == ""){
var latestPick = i;
break;
}
}
var subject = sheet.getRange(i+1, 2).getValue();
var body = sheet.getRange(i+1, 1).getValue();
MailApp.sendEmail(recipient, subject, body);
}

Send automated email for specific value of a drop down column

I have tried many different codes to send an email alert when column F in my Google sheet has the value "Yes". I am selecting this value from a drop down. But no emails are sent. I have tried different emails also. Nothing works. This is the code I am trying right now.
function Email(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName("FY");
var row = s.getActiveRange().getRow();
var status = s.getRange(row,6).getValue();
var subject = 'subject'; var message = 'body';
var email ="";
if (e.value === "Yes" && e.range.getColumn() === 6) {
GmailApp.sendEmail(email,subject,message);
}
};
You need to use an installed trigger see here to use this on edit script.
Go to 'Edit' -> 'Current project's triggers' and set a trigger as shown below.
Code:
function onEdit(e){
var getRange = e.range;
var getValue = getRange.getValue();
var getCol = getRange.getColumn();
if(getValue == "Yes" && getCol == 6){
var subject = 'subject';
var message = 'body';
var email = "---------------";
MailApp.sendEmail(email, subject, message);
}
}

Google Spreadsheet - How to write the correct If statement and Browser.msgBox return function

I am try to figure out is, how to write the if statement, so that it will send a separate email based on the two values it will check in the spreadsheet.
Here are the two values that are in Column N:
"In Progress"
"Completed"
Here is the code section:
var sheetNameToWatch = "Active Discs"; // Active spreadsheet that contains the data
var columnNumberToWatch = 14; // Column N
var valueToWatch1 = "In Progress"; // First value to watch for in column N
var valueToWatch2 = "Completed"; // Second value to watch for in column N
/*var valueToWatch3 = "Rejected"; // Third value to watch for in columns for labeled PM Review and Date Discs Shipped*/
var timestamp = new Date(); // Timestamp
var activeSessionuser = Session.getEffectiveUser(); //Get the current user in the spreadsheet
var replyTo = 'test#test.com';
function sendEmailNotifications(e) {
//Logger.log(JSON.stringify(e));
try{
var ss = e.source;
var sheet = ss.getActiveSheet();
var range = e.range;
//Checks the variables sheetNameToWatch + columnNumberToWatch + valueToWatch1 ("in progress")
//Sends Email to Venue Colombo Team
if (sheet.getName() == sheetNameToWatch && range.columnStart == columnNumberToWatch && (e.value == valueToWatch1)){
var confirm = Browser.msgBox('Email will be sent to the Venue Colombo Team. Do you want to sent this email?', Browser.Buttons.YES_NO);
if(confirm.toLowerCase()=='yes'){sendColomboMessage(e.range.rowStart)};
SpreadsheetApp.getActiveSpreadsheet().toast('Email Sent to Venue Colombo Team')
}
This section I am stuck trying to write the "else" or "else if" statement that will watch for value "Completed and send a different email.
else (sheet.getName() == sheetNameToWatch && range.columnStart == columnNumberToWatch && (e.value == valueToWatch2)){
var confirm = Browser.msgBox('Email will be sent to the Venue Colombo Team. Do you want to sent this email?', Browser.Buttons.YES_NO);
if(confirm.toLowerCase()=='yes'){sendVCSMessage(e.range.rowStart)};
SpreadsheetApp.getActiveSpreadsheet().toast('Email Sent to VCS Team')*/
}catch(err){Logger.log('catch err = '+err)}
}
Lastly, when I add "return;" to the code for the Browser.msgbox, it does not stops the code from running or the entire function stops working. Where or how do I add the return; if the user click "No". Then it should close the message box and do nothing.
if(confirm.toLowerCase()=='yes'){sendColomboMessage(e.range.rowStart)};
SpreadsheetApp.getActiveSpreadsheet().toast('Email Sent to Venue Colombo Team')
This should do what you are after (there is a lot of repeated functionality that could be broken out into another function):
var sheetNameToWatch = "Active Discs"; // Active spreadsheet that contains the data
var columnNumberToWatch = 14; // Column N
var valueToWatch1 = "In Progress"; // First value to watch for in column N
var valueToWatch2 = "Completed"; // Second value to watch for in column N
/*var valueToWatch3 = "Rejected"; // Third value to watch for in columns for labeled PM Review and Date Discs Shipped*/
var timestamp = new Date(); // Timestamp
var activeSessionuser = Session.getEffectiveUser(); //Get the current user in the spreadsheet
var replyTo = 'venueclientservices#rrd.com';
function sendEmailNotifications(e) {
Logger.log(JSON.stringify(e));
Logger.log('sendEmailNotifications()');
try {
var ss = e.source;
var sheet = ss.getActiveSheet();
var range = e.range;
var ass = SpreadsheetApp.getActiveSpreadsheet();
var confirm;
var getName = sheet.getName();
var columnStart = range.columnStart;
Logger.log("getName: " + sheet.getName());
Logger.log("columnStart: " + range.columnStart);
Logger.log("e.value: " + e.value);
if (getName == sheetNameToWatch &&
columnStart == columnNumberToWatch) {
if (e.value == valueToWatch1) {
Logger.log("Value 1");
confirm = Browser.msgBox('Email will be sent to the Venue Colombo Team. Do you want to sent this email?',
Browser.Buttons.YES_NO);
if (confirm.toLowerCase() == 'yes') {
sendColomboMessage(e.range.rowStart)
ass.toast('Email Sent to Venue Colombo Team')
} else {
ass.toast('Edit In Progress but no email sent');
}
} else if (e.value == valueToWatch2) {
Logger.log("Value 2");
confirm = Browser.msgBox('Email will be sent to the VCS Team. Do you want to sent this email?',
Browser.Buttons.YES_NO);
if (confirm.toLowerCase() == 'yes') {
sendVCSMessage(e.range.rowStart);
ass.toast('Email Sent to VCS Team');
} else {
ass.toast('Edit Value 2 but no email sent');
}
} else {
ass.toast('Edit, but no email sent.');
}
} // matching sheet and col
} // try
catch (err) {
Logger.log('catch err = ' + err);
}
function sendColomboMessage(row) {
Logger.log("sendColomboMessage, row: " + row);
};
function sendVCSMessage(row) {
Logger.log("sendVCSMessage, row: " + row);
};
} // sendEmailNotifications()