Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
How do I limit the characters pulled from getBody in apps script

I'm trying to pull data from gmail (ie. from, to, date, subject, body, etc.) but I'm getting an error saying the getBody() length is too long:

your input contains more than the maximum of 50000 characters in a single cell

I'm trying to have a cut off of characters or just not pull the email with a Body over the character limit. Also, I'm pretty out of practice on this and it's not working...

//Allow user to select label(s) and date range
function getGmailEmails() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var label = sheet.getRange(1, 3).getValue();
  var after = sheet.getRange(2, 3).getDisplayValue();
  var before = sheet.getRange(3, 3).getDisplayValue();
  var threads = GmailApp.search("label:" + label + " AND " + "after:" + after + " AND " + "before:" + before);

  // Export emails into table of values in google sheet
  // Character length cutoff is 2000, the cell with get Body would tell you to go to the inbox
  var values = [];
  for (var i = 0; i < threads.length < 2000; i++) {
    var temp = [];
    var label = threads[i].getLabels().map(e => e.getName()).join(", ");
    let messages = threads[i].getMessages();
    for (var j = 0; j < messages.length; j++) {
      temp.push([
        label,
        messages[j].getFrom(),
        messages[j].getTo(),
        messages[j].getCc(),
        messages[j].getDate(),
        messages[j].getSubject(),
        messages[j].getBody(),
        messages[0].getId()
      ]);
    }
    values = values.concat(temp);
  }
  sheet.getRange(6, 1, values.length, values[0].length).setValues(values);
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

One way is by using String.prototype.slice().

Replace

messages[j].getBody(),

by

messages[j].getBody().slice(0,50000),

Related

  • Substring vs Slice vs Other?
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda