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

113
Views
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 answers
Answer question

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 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!