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

114
Vistas
Cannot read property from undefined - Google Script

I have issues with this code, I can't make JSON splitting part correctly. I constantly get the following error: TypeError: Cannot read property "cu_id" from undefined.

part of JSON data looks like this (it is too big to show all, but the rest is the same)

{"started":"2022-01-15T12:56:08.197","finished":"2022-01-15T12:56:08.207","action":"RECEIVE","status":"SUCCESS","username":"sciarlo","subject":"340382659301954864","object":"10834376","result":"Created lots 5265995","trace_id":"LC3tS16A","properties":{"arrival_id":"ARR-98fc5b2b-cad2-4033-9bff-3af5cd779946","cu_id":"10834376","cu_quantity":"62","freshness_date_format":"NONE","load_carrier_barcode":"340389301954864","location":"3403826554864","purchase_orders":"366469","receive_type":"SSCC","temperature_zone":"AMBIENT","tu_id":"10834376","tu_quantity":"62"}}

Here is the part of code with issues:

  var receiveActions = []
  var latestTimestamp = receiveTab.getRange(2, 19).getValue();
  var actionTime = new Date(outputArray[0].finished)
  receiveTab.getRange(3, 19).setValue(actionTime);

  for (var i in outputArray) {
    var receiveAction = outputArray[i];
    if (new Date(receiveAction.finished) > new Date(latestTimestamp)) {
      
      var article = receiveAction.properties.cu_id;
      var location = receiveAction.properties.location;
      var temperatureZone = receiveAction.properties.temperature_zone;
      var cuQuantity = receiveAction.properties.cu_quantity;
      var tuQuantity = receiveAction.properties.tu_quantity;
      var tuSize = cuQuantity/tuQuantity;
      var timestamp = new Date(receiveAction.finished);
      var user = receiveAction.username;
      
      receiveActions.push([timestamp,user,temperatureZone,article,location,tuQuantity,tuSize])
    }
  }

Thank you in advance for help!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your JSON is not valid, it begins with a bracket/array but doesn't end with a bracket/array.

This makes me feel that you have more than one object entry in your JSON, and that the one you're showing us isn't the problem.

Are you sure that all of your objects in the JSON structure contains the receiveAction.properties element?

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