Encountered an issue while attempting to access a property from an undefined source

I am struggling with this code as I am unable to correctly split the JSON data. The error message I keep encountering is: TypeError: Cannot read property "cu_id" from undefined.

Here is a snippet of the JSON data (since it's too large to display entirely, but the remaining part is consistent)

{"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",...

Below is the portion of the code causing 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])
    }
  }

Your assistance with this issue is greatly appreciated!

Answer №1

It seems like there is an issue with the validity of your JSON format as it starts with a bracket/array but does not end with one.

This indicates that there may be multiple object entries in your JSON, and the one being displayed might not be the source of the problem.

Have you confirmed that all objects within the JSON structure include the receiveAction.properties element?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Despite modifying the ID in the response data of Angular MongoDB, the request data ID remains unchanged

Having trouble with managing requests and responses, specifically when a customer tries to add multiple items of the same product but in different sizes. The initial step involves checking if the ID exists by using a count and an if statement. If it exists ...

What is causing the click function to malfunction after selecting a second item?

I'm struggling to understand why my click function isn't functioning properly. You can view the JSFiddle here: http://jsfiddle.net/adbakke/ve9oewvh/ This is a condensed version of my HTML structure: <div class="projectDisplay"></div&g ...

Interact with multiple databases using the singleton design pattern in a Node.js environment

I need to establish a connection with different databases, specifically MongoDB, based on the configuration set in Redis. This involves reading the Redis database first and then connecting to MongoDB while ensuring that the connection is singleton. Here i ...

What could be the reason for the history.length being 2 on the initial page?

Why is it that when I open a new browser window and load a page in it, the history.length property is always 2 in both Chrome and Firefox? You can test this phenomenon yourself by visiting the following link: http://jsbin.com/amiyaw ...

Incorporate controllers dynamically into your Angular application

Currently, I am incorporating AngularJS into a Backbone.js application. The scenario is as follows: I have one controller (let's call it controller1) which is added to the Angular app from a Backbone view (referred to as view1). Subsequently, I introd ...

Encountering an Uncaught Error: MyModule type lacks the 'ɵmod' property

I am currently working on developing a custom module to store all my UI components. It is essential that this module is compatible with Angular 10 and above. Here is the package.json file for my library: { "name": "myLibModule", &qu ...

Get the ability to overlay text onto an image by using jQuery for downloading

Currently, I am facing an issue with an online photo editor in my project. The problem is that I am unable to download the image after adding and editing text on it. The texts added are editable but the image cannot be downloaded after the changes. I nee ...

Tips for cropping an image using CSS with dimensions specified for width, height, and x and y coordinates

As I work on implementing a cropping feature using react-easy-crop, my goal is to store the user's image along with pixel coordinates that dictate their preferred cropping area. My objective is to utilize the parameters provided by react-easy-crop in ...

Angular material table cell coloring

Here is my current setup: I have an array of objects like this: users : User []; average = 5; compareValue (value){ ...} And I am displaying a table as shown below: <table mat-table [dataSource]="users"> <ng-container matColumnDef= ...

"Patience is key when it comes to waiting for components to render

Short Overview of the Issue I'm currently exploring methods to access an onRendered lifecycle hook. Finding on the Topic A similar query was posted here: Vue $nextTick in mounted() hook doesn't work as expected The explanation provided suggests ...

Restrict the number of labels on Chart.js exclusively for smaller displays

How to Limit the Number of Labels on a Chart.js Line Chart I am looking for a way to decrease the number of labels on my line chart only when it is viewed on a small device. The solution provided in the previous post suggests using the following code: xAx ...

Troubleshooting Problems with Ajax across Different Web Browsers

I am facing an issue with my ajax function - it works perfectly on Chrome and Firefox, but not on Internet Explorer 8. Can anyone help me identify the problem? Here is the HTML section: <select id='choices'> <option id="no" value="no" ...

What's the best way to prevent extra spacing when typing in a materialUI TextField?

Instructions for the user: Please input your first name without any spaces between characters. I attempted to implement the following code, however, it did not achieve the desired outcome. <TextField required id="name" label="First Name" ...

Conceal image and substitute with a different image using JavaScript

My query pertains to JavaScript: how can I create an effect where clicking the jump-down button opens a text box and causes the button to change direction and rotate? I am considering using two photos - one hides when the jump-down button is clicked, and ...

How to get the total number of rows/records in a JSON store using ExtJS?

My dilemma involves a JSON store that provides data in JSON format. I am currently attempting to determine the number of rows or records in the JSON string. However, when utilizing the store.getCount() function, it consistently returns 0. Strangely, the ...

When attempting to pass Rgraph image data through a jQuery AJAX call, a 403 Forbidden error is being

I have been working on a project that involves creating graphs/charts using the Rgraph PHP library. To generate these charts, my script follows these steps: Calculate the graph points and render the graph using the Rgraph Draw() method. Create an image d ...

Contrasting include versus block in Jade

Can you explain the distinction between blocks and include in Jade template creation? How do you determine when to use each one? ...

Exploring the process of setting up a datasource for Select2 in October CMS using the integrated Ajax Framework

Looking to utilize the extensive AJAX framework provided by October CMS to populate a Select2 box with data. The process of using a remote dataset in Select2 involves the following steps: $(".js-data-example-ajax").select2({ ajax: { url: "https://a ...

Transmitting a key-value pair data object to the server-side code-behind aspect

Transferring a key value pair object to the server side codebehind. What is the method to send it from JavaScript? And how can it be received in C# codebehind? Modification 1 <script type="text/javascript"> function ABC() { va ...

Is there a way to make sure that ngbpopovers stay open even when hovering over the popover content?

I have implemented a ngbpopover to display user information on an element. Currently, the popover is triggered on both hover and click events, but I would like it to remain open when hovered over, instead of closing as soon as the mouse moves away. How c ...