Displaying values from a JSON array in a BIRT report

I'm facing an issue with printing JSON values from a database column in my Birt report. It seems to only display the last line of the JSON array, rather than all the lines before it.

Below is the code for my dynamic text field:

var phone = JSON.parse(row["c_numbers"]);
for(var k in phone) {
    phone[k]['type']+': '+phone[k]['phone']
}

This is the output currently displayed:

https://i.sstatic.net/MDSEc.png

And here is the JSON data retrieved from the database:

[{"type": "Cell", "phone": "123-123-1233"}, {"type": "", "phone": "123-423-4123"}]

While I am able to fetch and iterate over the JSON data successfully, the report design only shows the last item in the array. Any suggestions on resolving this issue would be greatly appreciated.

https://i.sstatic.net/70Zg5.png

It seems like the script is fetching the data correctly, looping through the JSON array, but only displaying the final element.

Answer №1

To solve the problem, I created a new variable to store the updated data and then displayed this final variable at the end. Additionally, I included <br> tags to create new lines in the output.

var phoneNumbers = JSON.parse(row["c_numbers"]);
var updatedPhoneNumbers = '';

for(var key in phoneNumbers) {
    updatedPhoneNumbers = updatedPhoneNumbers + (phoneNumbers[key]['type'] > '' ? phoneNumbers[key]['type']+': ' : '') + phoneNumbers[key]['phone'] + "<br>"
}

updatedPhoneNumbers;

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

Leveraging a variety of Clone functions in Java

I am currently working on a program that involves two main classes, test001 and test002. Test001 is responsible for creating a shallow copy of Appointment objects, while test002 creates a deep copy. To support both functionalities, I need to add some cod ...

I'm in need of some assistance - could somebody kindly point out where I may be making

I'm encountering an issue where I'm only receiving two rows of data from the database instead of four. I've reviewed my code but can't seem to pinpoint any problems. Can anyone assist me with this? Here is the code snippet: $sql = mys ...

How to select the first column in a jQuery Datatable and turn it into checkboxes

I'm faced with a situation where I need to incorporate a checkbox column in a table, with the checkboxes appearing as Checked or Unchecked based on the values in the first column and its subsequent rows. The challenge lies in dealing with dynamic data ...

Deciphering and Organizing JSON Data from Twitter Streams

I'm having difficulties with the formatting and encoding of the Twitter stream collected by a Python script I wrote. The output is displaying as shown below: {"created_at":"Wed May 07 20:53:05 +0000 2014", "id":46414592 ...

Encountering a "Web Storm identifier expected" error while attempting to pass Vue function parameters using braces

This is the code I've been working on. I encountered an error while coding. Can you help me figure out how to address this issue? Should I consider disabling the inspection feature in WebStorm, or should I make changes to the code style? I have alre ...

What is the best way to make an element fixed vertically in a mobile browser while also enabling horizontal scrolling?

When using a Desktop browser, I have found a javascript code that allows me to vertically fix an element while still enabling horizontal scrolling. The element is repositioned with each scroll event. You can test this out by trying both horizontal and vert ...

Using JavaScript to invoke a jQuery function

I'm currently working with jQuery and JavaScript, and I have a requirement where I need to invoke a jQuery function from within my JavaScript code. This is the jQuery function in question: function showData(id){ $.ajax({ type:'POST& ...

Mastering keyframe animation with Three.js

Hello everyone, I am new to posting and I have a question that I haven't been able to find the answer to anywhere else. Just to clarify, I am not a professional programmer, more of a 3D graphic designer ;) I am interested in importing json models wit ...

How to perform JSON parsing with the Jackson Parser in an Android application?

As a newcomer to Android development, I am currently working on a project that involves parsing JSON data by making a URL call. Initially, I was able to successfully achieve this using the built-in JSON parser provided by Android. However, when attempting ...

Utilizing JSON data extraction technique to send it as props in Next.js application

I'm facing a dilemma at the moment: To populate the DataGrid component, I need to pass props As a result, I've employed getStaticProps to retrieve JSON data from an API and send it back as props. The catch is, I only require 3 attributes from ea ...

What steps can be taken to retrieve data from a database table using JavaScript?

I am encountering a very peculiar issue. The values that I need are visible when I receive them as a message from the server-web console. However, when I try to retrieve them using a for loop, I encounter an error 05-22 18:58:23.203: I/Web Console(29392): ...

Iterating over a string to remove specific characters

While iterating through lines of text and checking for brackets in each line, I encountered a problem with deleting the last closing bracket. Despite working well for the other brackets, the very last one gets missed for some unknown reason. I have made se ...

The issue of excessive new lines appearing during JSON encoding is encountered when responding

When using the print_r method to display an array: Array ( [0] => Array ( [id] => 44 [item_level] => 0 [position] => 10 [parent_position] => [title] => PHP Tutorial ...

Cypress and VueJS: How to target elements that are dynamically generated following a specific user interaction

I am currently testing a new feature where a button will only appear for the user to click after they have completed another action. Before proceeding with the action, I am verifying if the button exists: cy.get('span') .contains('Selec ...

Tips for generating documentation using markdown within the docs directory on GitHub with the help of JavaScript

After browsing through numerous documentation websites, I have noticed that many of them share the same layout and features. This has led me to question whether there is a common library used by all these documentation sites. How do they achieve this unif ...

Having issues with the basic KnockoutJS binding not functioning as expected

There appears to be an issue with my KnockoutJS script that I'm struggling to pinpoint. Below is the snippet of HTML code: <h2>SendMessage</h2> <div class="form-group" id="messageSender"> <label>Select User Type</l ...

Extracting information from Postgres and converting it to JSON format while dynamically updating the column names

Is there a way to selectively import specific columns from a table in json and alter their names during the process? For example: MyTable (id, column1, column2, columns3) I aim to transform them into json format as follows: MyTable: {column11, column2, ...

Redraw only a specific offspring

Currently, I am in the process of constructing a dynamic form and my component hierarchy looks like this:- App Caseform DynamicFormBuilder Context.Provider Patients Patient key = "patient_1" ComponentCrea ...

Using C# and Javascript with Selenium

As we delve into our project, we are exploring the best approach for testing between these two options: 1. Selenium with C# 2. Selenium with Java Script Upon researching, I discovered that using C# requires Selenium libraries and NUnit framework. However, ...

Ensure the central alignment of the focused item within the horizontal scroll

I have successfully implemented a horizontal scroll container using <HTML/> and CSS: body { background-color: #212121; } .scroll_container { height: 100px; width: 400px; display: flex; align-items: center; overflow-y: hidden; width: 1 ...