Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

301
Views
How to get lastRow from array of data from Google Sheet array?

I'm having no knowledge of JS or any leng, this code just fits me the best. So what I need to do, is to receive the last row from array which corresponds to today's date 13.10 today -> 13.10 today a row was added and send it to bot in Telegram, but the entire array is sending, like all rows from that array that contains 12.10.2021, 13.10.2021, etc.

This code should take the last added line (s) to the table depending on the date, if today's date is next to the line - this line is sent as a message in telegram.

But I have no idea how to force it to get last row(rows) from array. enter image description here

 const token = "my Token";

function timer() {
  let ss = SpreadsheetApp.getActiveSpreadsheet();
  let ws = ss.getSheetByName("SheetName");
  let data = ws.getRange(2, 1, ws.getLastRow()-1, 10).getValues();
  // console.log(data)
  let curentTime = new Date().getDate() + "." + (new Date().getMonth() + 1) + "." + new Date().getFullYear();
  // console.log(curentTime)

  for (i = 0; i < data.length; i++) {
    let dataInfo = data[i];
    // console.log(dataInfo)
    let clientName = dataInfo[3];
    // console.log(clientName)
    let clientBirthday  = dataInfo[0].toString();
    //  console.log(clientBirthday)
    let clientIdChat = "myID";
    if (dataInfo[0] !== ""){
      clientBirthday = dataInfo[0].getDate() + "." + (dataInfo[0].getMonth() + 1) + "." + dataInfo[0].getFullYear();
      // console.log(clientBirthday)
    }
    
    if (clientBirthday == curentTime){
        sendText(clientIdChat,data.toString());
      

      
    }
  }
  

// console.log(curentTime)
}
 
function sendText(chatId, text, keyBoard) {
  let data = {
    method: 'post',
    payload: {
      method: 'sendMessage',
      chat_id: String(chatId),
      text: text,
      parse_mode: 'HTML',
      reply_markup: JSON.stringify(keyBoard)
    }
  }
  UrlFetchApp.fetch('https://api.telegram.org/bot' + token + '/', data);
}
> A/Дата надходження    B/Компанія    C/ІПН D/ПІБ E/Номер справи    F/Суд G/Область
 H/Місто відповідача   I/Адреса відповідача  J/Посилання на документ
> A/12.10.2021  B/A   C/1   D/Name    E/111/3433/99                 J/Link to document
> A/13.10.2021  B/B   C/2   D/name    E/111/3433/99                 J/Link to document
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I believe there are 2 issues:

  1. the sendText should be nested inside the for loop, so you are only executing that once you've matched the birthday
  2. the sendText formula should be sending dataInfo.toString not data.toString, since dataInfo reflects the current row while data is the entire array

I've re-written that segment of the code:

  for (i = 0; i < data.length; i++) {
    let dataInfo = data[i];
    // console.log(dataInfo)
    
    let clientBirthday  = dataInfo[0].toString();
     console.log(clientBirthday)

    if (clientBirthday == curentTime){
          let clientName = dataInfo[3];
          //console.log(clientName)
          let clientIdChat = "myID";
          sendText(clientIdChat,dataInfo.toString());
    }
  }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!