Hi everybody:)
I’m now need the appscript that help me to send email when page “Leave (Approved)” have changes.
So, i’m using this script but i’m not getting any email. Can you guys check whether my script is right ?
Summary
var changedFlag = false;
var TEMPLATESHEET='Leave (Approved)';
function sendemailtoHR() {
DocumentApp.getActiveDocument();
DriveApp.getFiles();
// This is the link to my spreadsheet with the Form responses and the Invoice Template sheets
// Add the link to your spreadsheet here
// or you can just replace the text in the link between "d/" and "/edit"
// In my case is the text: 17I8-QDce0Nug7amrZeYTB3IYbGCGxvUj-XMt8uUUyvI
const ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1QJfyJZt5_9s3Qh2xatz2OUPgDPtfiN-g-FeatEoGPFo/edit");
// We are going to get the email address from the cell "B7" from the "Invoice" sheet
// Change the reference of the cell or the name of the sheet if it is different
const value = ss.getSheetByName("Leave (Email)").getRange("P3").getValue();
const email = value.toString();
// Subject of the email message
const subject = ss.getSheetByName("Leave (Email)").getRange("Q3").getValue();
// Email Text. You can add HTML code here - see ctrlq.org/html-mail
const body = ss.getSheetByName("Leave (Email)").getRange("R3").getValue();
// Again, the URL to your spreadsheet but now with "/export" at the end
// Change it to the link of your spreadsheet, but leave the "/export"
const url = 'https://docs.google.com/spreadsheets/d/1QJfyJZt5_9s3Qh2xatz2OUPgDPtfiN-g-FeatEoGPFo/export?';
// You can find the sheet ID in the link bar.
// Select the sheet that you want to print and check the link,
// the gid number of the sheet is on the end of your link.
var params = {method:"GET",headers:{"authorization":"Bearer "+ ScriptApp.getOAuthToken()}};
}
function on_sheet_change(event) {
var sheetname = event.source.getActiveSheet().getName();
var sheet = event.source.getActiveSheet();
if (sheetname == 'Leave (Approved)') {
sendemailtoHR() ;
} else return;
}
and i add the trigger: