Parse a json list into separate string objects to store in entity

0
 Hi,   Very new but have taken both the rapid developer and crash course but was not able to determine an answer.   1. I am calling an api that returns a json object - mapping and import works fine. 2. I created a button on my home page to call the api via microflow 3. The microflow works and a message is returned containing the results:   The settings I used on the microflow are: I noted that the return message is the same if I select either: * Store in an HTTP response * Store in a string   This is all fine, but what I would like to do is store the returned message in an entity, so:   1. I don't recall but I believe the entity for the json response is created automatically  2. I made the entity persisent and also selected the option to Generate Overview Pages and let Mendix autofill the Overview page 3. When I re-run and call the microflow from the Homepage button, it again works, but the Overview page is not populated with the response 4. I then modified some settings:     a. I changed the Response handling to Apply import mapping and selected the Range as First and Commit to Yes      b. I updated Show Message to capture the response     When I re-ran things: the message returns the first element in the response, and populates the entity - the overview is also populated with that first element:     This is great but what I would like to do is return the entire message and populate the entity with the individual elements of the response as:     I attempted to do this by: 1. Changing the Range  in the rest Response dialog to All 2. Updating the message (file list(1))   As can be seen there is an error - and one that I cannot resolve - I did ask MAIA and did some search to try and resolve but no concrete resolution The outcome that I would like is to be able to parse the return response to ensure each element appears as a separate object in the entity and on the overview page as:     Finally, pardon the long message, however I hope this makes sense and any assistance/advise is greatly appreciated.   Thank you!   Michael
asked
3 answers
0

Hi Michael,

I think uou’re on the right track with your implementation. The error occurs because you’re trying to show a list of objects directly in a message popup, which isn’t supported.

When you use Range = All in the import mapping, the API response is stored in a list of objects. That list can then be committed to the entity and displayed on your overview page, which seems to be your actual goal.

If you also want to show a confirmation message, you have two options:

  1. Iterate over the list and build a custom message (or just display something simple like “Update successful” instead of the full list).

  2. As Erwin suggested, import by import from json, then use that string in the message popup if you need to display the raw response.

Once you close the popup, you should see the imported data on your overview page as expected.

 

Hope this helps !! 

 

answered
1

If you create a json structure like below

image.png

Then create an import mapping based on this json structure the data is completely imported. In an example I have this microflow:

image.png

In the first action I create a string with [{"fname":"data_A.csv"},{"fname":"data_B.csv"},{"fname":"data_C.csv"}]

In the second action I import the data with the mapping below:

image.png

And the result is shown in the overview page:

image.png

The import should be paossible by using the import mapping directly in your response handling of yoou rest call.

Hope this helps in finding the solution.

answered
1

thank you both for your help - thank you Erwin for the detailed solution. I was able to find a solution prior to the post being updated and this in line with what Neha suggested - after selecting Range as ALL from CALL REST (GET) block, I created a string from the results and iterated over that to - the ensure each elements in the json object was committed to the entity as a separate object:

 

m10.jpg

 

 

As I want to check intermittently for files added to the directory I also added retrieve and delete objects activities prior to the call - I will also suppress the return to a success message.

 

thank you again and in future if I find a solution to a posted issue I will update more efficiently.

 

Regards,

 

Michael

answered