I have related entities that I want to create a json file from. This json file contains nested data and I am not sure how to create the final json for the different scenarios of data. I would also want to download the json file when a button is clicked.My entities hold data for OrderInfo, MedItem and MedItemDose How would I create the following json:
{
"OrderInfo": {
"OrderNum": "1677746289",
"Note": "",
"DataClsf": "N",
"MedItem": [
"MedCd": "319283006",
"MedNm": "Amlodipine 5mg tabs",
"UseAtcYn": "Y",
"MedSpec": "--",
"MedNote": "Do not take with any Grapefruit Products at the same time as this medicine.",
"GroupNum": "1",
"MedItemDose": [
"TakeDt": "20230418",
"UserExpDate": "20230902",
"DoseList": "Breakfast:1.00;EVENING:0;Night:0",
"DoseNote": "1-277-10446-1-967E;1-277-10449-1-954E;1-277-10452-1-AB3E",
"DrtsCd": ""
},
"TakeDt": "20230419",
"DoseNote": "1-277-10455-1-6A8F;1-277-10458-1-A91E;1-277-10461-1-EFCE",
}
]
"MedCd": "320031002",
"MedNm": "Atorvastatin 40mg tabs",
"DoseList": "Breakfast:0;EVENING:0;Night:1.00",
"TakeDt": "20230515",
"DoseNote": "1-277-10689-1-534;1-277-10692-1-3B44;1-277-10695-1-FAF5",
"MedCd": "424513004",
"MedNm": "Sitagliptin 50mg tablets",
"MedNote": "",
"DoseList": "Breakfast:1.00;EVENING:1.00;Night:0",
Thank you for sharing.You will have to change your approach to handle the nested list structures.I have made a simple example, wich showcases the concept that you need to implement in your code.In my example i'm using 3 different aggregates to collect the data just to keep it as simple as posssible. You could also use 1 DB call and use the listfilter widget.I hope this clarifies ! Kind regardsThibaut
Hi Mganda,
write an action that creates a list of records or simply fetch data from adv, sql or aggregate and then use the JSONSerialize action.
Thanks
CV
1. Define the Structure: First, define the structure of your JSON object. (See example)
2. Populate the Object: Populate your 'OrderInfo' object with the necessary data.
3. Serialize the Object: Use the 'SerializeJson' widget to convert your 'OrderInfo' object into a JSON string.
Kind Regards
Thibaut
This is the general direction i am taking. I will need more guidance to be alittle bit more specific.
I then created a server actionThen created a client action on my screen that is triggered by clicking a link:Unfortunately, the file that is downloaded on button click has nothing in it.Where am I going wrong?
I added a breakpoint on my client action where my server action is on debug.The debug path goes from the switch statement to the end instead of going through the other route(if statement, assign, json serializer ...)
Can you share the OML?
Now my biggest problem is that am not getting all the data that I need in my Json download.I am getting data from OrderInfo section of the Json but now the MedItem or MedItemDose which are nested arrays. The following Json is what am currently getting:{"OrderInfo":{"OrderNum":"34","OrderDt":"03-04-2024","OrderDtm":"03-04-2024","MdctNum":"","MdctDt":"","PtntNum":"13","PtntNm":"Dominic Calvert-Lewin","Sex":"Male","Birthday":"01-01-1999","PtntAddr":"Address 1 Address 2","InOutClsf":"I","HsptCd":"","HsptNm":"","DptmtCd":"0","DoctorNm":"Dych","WardCd":"","WardNm":"","RoomNum":"","EmgClsf":"0","DschClsf":"0","OrderClsf":"0","Note":"","DataClsf":"N","DspsOpt":"5|R^Y^Y|Test Bundesliga Layout|Y","MedItem":[]}}When I debug the application, I could see all data including those for MedItem and MedItemDose as shown in the image below:
My OML is bigger that 4MB, so can't be attached.
Since my OML's size is bigger that 4MB, I am sharing a link to a google drive
I believe yours is the right process but am still experiencing similar issues where am able to get OrderInfo related info but not MedItem or MedItemDose data in my json download.
When debugging, I can see the expected MedItem and MedItemDose related data but an error pops up when stepping out
Can you share the new OML?
Hi Mganda.
Probably the query JSONData returns no record and therefore the execution goes straight forward to the end. Is it the case?
I cannot understand what is assigned in the "Assigns" of the TestJsonDownloadServerAction.
There a local variable in the server action(EEVEE_OUTPUT) whose data type is the structure. The assign is used to populate this local variable with values from the database.Then, that local variable is used as the input to the json serializer. Right now, my serialized json gives me data up to DspsOpt part leaving MedItem empty and MedItemDose nonexistent.{"OrderInfo":{"OrderNum":"35","OrderDt":"03-04-2024","OrderDtm":"03-04-2024","MdctNum":"","MdctDt":"","PtntNum":"17","PtntNm":"Bukayo Saka","Sex":"Male","Birthday":"05-05-2000","PtntAddr":"Address 1 Address 2","InOutClsf":"I","HsptCd":"","HsptNm":"","DptmtCd":"0","DoctorNm":"Arteta","WardCd":"","WardNm":"","RoomNum":"","EmgClsf":"0","DschClsf":"0","OrderClsf":"0","Note":"","DataClsf":"N","DspsOpt":"5|R^Y^Y|Test EPL Layout|Y","MedItem":[]}}
I found some issues: