尝试
function onEdit(e) {
let sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
let sheetName = sheet.getName(); // Get the name of the active sheet
// EVENT VARIABLES
let range = e.range;
let row = e.range.getRow();
let col = e.range.getColumn();
let cellValue = sheet.getActiveCell().getValue();
let projectName = sheet.getRange(row,1).getValue();
let user = Session.getActiveUser().getEmail();
let cellLocation = sheet.getActiveCell().getA1Notation();
let url = "https://docs.google.com/spreadsheets/d/1bAJ0Asma4lX1tW3HYezW_Al6llkpaIKWSLptfjV-pAI/edit#gid=712318935";
if (col == 1 && cellValue == "NEW") {
let recipientEmail;
// Determine the recipient based on the sheet name
if (sheetName === "Tab 1") {
recipientEmail = '[email protected]';
} else if (sheetName === "Tab 2") {
recipientEmail = '[email protected]';
} else if (sheetName === "Tab 3") {
recipientEmail = '[email protected]';
} else if (sheetName === "Tab 4") {
recipientEmail = '[email protected]';
}
if (recipientEmail) {
MailApp.sendEmail(
recipientEmail,
'Staff Overview Update',
"There has been an update to the " + sheetName + " sheet requiring your attention: " + url + '&range=' + cellLocation,
{name: 'Team Leader'}
);
}
}
}
更新
function onEdit(e) {
let sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
let sheetName = sheet.getName(); // Get the name of the active sheet
let sheetId = sheet.getSheetId(); // Get the unique ID of the active sheet
// EVENT VARIABLES
let range = e.range;
let row = e.range.getRow();
let col = e.range.getColumn();
let cellValue = sheet.getActiveCell().getValue();
let projectName = sheet.getRange(row,1).getValue();
let user = Session.getActiveUser().getEmail();
let cellLocation = sheet.getActiveCell().getA1Notation();
let baseUrl = "https://docs.google.com/spreadsheets/d/1bAJ0Asma4lX1tW3HYezW_Al6llkpaIKWSLptfjV-pAI/edit";
if (col == 1 && cellValue == "NEW") {
let recipientEmail;
// Determine the recipient based on the sheet name
if (sheetName === "Tab 1") {
recipientEmail = '[email protected]';
} else if (sheetName === "Tab 2") {
recipientEmail = '[email protected]';
} else if (sheetName === "Tab 3") {
recipientEmail = '[email protected]';
} else if (sheetName === "Tab 4") {
recipientEmail = '[email protected]';
}
if (recipientEmail) {
let url = `${baseUrl}#gid=${sheetId}&range=${cellLocation}`;
MailApp.sendEmail(
recipientEmail,
'Staff Overview Update',
`There has been an update to the ${sheetName} sheet requiring your attention: ${url}`,
{name: 'Team Leader'}
);
}
}
}