Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting values from cells in google scripts

I am trying to make working sheets for my work. In Google scripts, I've created "Custom Menu" for my sheet wich is sending email correctly. But now I want to get value from the specific cell and check if it is below, for example, 2, send an email with that value. For now, I have this:

function onOpen() { 
  var ui = SpreadsheetApp.getUi();
  // Or DocumentApp or FormApp.
  ui.createMenu('Custom Menu')
      .addItem('First item', 'menuItem1')
      .addSeparator()
      .addToUi();
}
function menuItem1() {
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
     .alert('You clicked the first menu item!');
  if( 'A1' > 3){
  MailApp.sendEmail('[email protected]', 'subject', 'message');
  }
}

I don't know how to get this value from this cell. This 'If" is just an example of what I am trying to do, I know it is not working. Thank you in advance for any kind of help.

like image 240
Kramar Avatar asked Mar 08 '23 21:03

Kramar


1 Answers

First, You need to find the sheet:

var sheet = SpreadsheetApp.getActiveSheet();

Then, you need to specify a cell range and get the value(s):

var value = sheet.getRange("A1").getValue();

You can browse the API for more functions here: https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app

like image 183
Roman Hocke Avatar answered Mar 19 '23 04:03

Roman Hocke