Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

186
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda