37
Views
3
Comments
I want to compare two data from JSON and display the different data in table.
Question
Service Studio Version
11.54.86 (Build 63808)

I am a beginner in OutSystems, and I need to create a table using JSON data from an API. Since this requires generating repeated tables in a loop within the table, I am encountering difficulties.

The JSON format is as follows:

"invoice":[

    {

        "date":"2024/10/01",

        "content":[

            {

                "customerNum": "AE12345678",

                "custumerName": "Microsoft”,

                "quantity": 10,

                "created": "2024/10/1",

                "updated": "2024/10/1"

            },{

                "customerNum": "LA12345678",

                "custumerName": "Amazon",

                "quantity": 20,

                "created": "2024/10/01",

                "updated": "2024/10/01"

            }

        ]

    },{

        "date":"2024/09/01",

        "content":[

            {

                "custumerNum": "AE12345678 ",

                "custumerName": "Microsoft”,

                "quantity": 50,

                "created": "2024/09/1",

                "updated": "2024/09/1"

            },{

                "custumerNum": "LA12345678 ",

                "custumerName": "Amazon",

                "quantity": 30,

                "created": "2024/09/01",

                "updated": "2024/09/01"

            }

        ]

    },{

        "date":"2024/08/01",

        "content":[

            {

                "custumerNum": "AE12345678 ",

                "custumerName": "Microsoft”,

                "quantity": 10,

                "created": "2024/08/1",

                "updated": "2024/08/1"

            },{

                "custumerNum": "LA12345678 ",

                "custumerName": "Amazon",

                "quantity": 20,

                "created": "2024/08/01",

                "updated": "2024/08/01"

            }

        ]

    }

]


As shown in the JSON, assuming I have the company's orders for the past three months, I need to divide the table into two sections:


The right side will display the latest month's order data.

The left side will display past order data.

The table will show data for only two months at a time for comparison (with the right side always displaying the latest month's data). The data on the left side can be changed to view different months using a dropdown menu.


Each order field will be compared, and if there are differences, the cell in the latest data column will have its color changed to indicate the discrepancy (except Date).


The table will be displayed vertically. The prototype of the table would look something like this:


2016-04-21 18-13-58
Nuno Rolo
 
MVP

Hi Tsai,

I did a quick search and found a few assets in the Forge that may help you with this task.

https://www.outsystems.com/forge/component-overview/16736/json-compare-o11

https://www.outsystems.com/forge/component-overview/17948/jsondiffer-o11

Now you need to test and see which one is best for your situation.

Please note that you will probably need to create a table on the page with the results that the asset provides.

Hope this helps any other doubt feel free to say.

Nuno Rolo

UserImage.jpg
Tsai Hung Wei

Thank you, Nuno

This component is very helpful for me, but besides comparing the JSON data.

I am also having issues with generating the table.I have tried several different approaches, but I couldn’t find a way to create the table using a loop-like method.

Perhaps I should consider a different approach to creating the table?

Vincent

2016-04-21 18-13-58
Nuno Rolo
 
MVP

Well, I would say that you should convert your JSON to an OutSystems structure list using JSON Deserialize widget. 

This way you have a list that can be used as the source of the Table.

Also sharing this article that explains the work of these widgets.

Hope this help.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.