I
I
Ilyas_B2020-07-06 06:08:38
Google Apps Script
Ilyas_B, 2020-07-06 06:08:38

How to write a condition in the GS macro by the name of the tab?

There is such a macro that sends me a notification by mail every time changes are made in the table, in column A, but the table has several tabs, but only one is needed, please tell me how to write a condition so that notifications come only when there is a change from the "Check" tab?
P.S. The macro is written without knowledge of JS, intuitively and on a napkin, so it may contain frilly or unnecessary lines, if there are comments, I will be glad to listen.

function Call(){
  var sheet = SpreadsheetApp.getActiveSpreadsheet();
  var range = sheet.getActiveRange();
  var data = range.getValues();
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var cell = ss.getActiveCell().getA1Notation()
  if(range.getColumn() == 1 ){
    if(Session.getActiveUser()!=('[email protected]' || '[email protected]')){
  MailApp.sendEmail('[email protected]', 'КМ внес поставку', 'в ячейку '+cell+' менеджером '+Session.getActiveUser());
} 
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Grigory Boev, 2020-07-06
@Ilyas_B

Like this:

var sheet = SpreadsheetApp.getActiveSpreadsheet();
const sheetName = sheet.getName(); // Тут получаем название вкладки
//...
if ((range.getColumn() == 1 )&&(sheetName==="Лист1")){//Проверяем
    if(Session.getActiveUser()!=('[email protected]' || '[email protected]')){
  MailApp.sendEmail('[email protected]', 'КМ внес поставку', 'в ячейку '+cell+' менеджером '+Session.getActiveUser());
} 
}

Or like this:
var sheet = SpreadsheetApp.getActiveSpreadsheet();
if (["Лист1","Лист2"].indexOf(sheet.getName())==-1) return;//Список листов на которых скрипт работает

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question