84
Views
10
Comments
Solved
Loop Structure Variables into Entities 
Question

I have pulled JSON data into my environment by using ardoJSON and the REST API feature. This made a structure with the necessary variables and attributes. I am trying to transfer the structure information into entities in the database.  I have run a preparation (pictured below) on my main screen to put values into the aggregate GetPatientInfo and I am calling the values into my screen through a table.  I keep getting an internal error message or no information shows up on the table when I try to run the program.


mvp_badge
MVP
Rank: #5
Solution

Ayushi, 

Change your code in the follow way. 

1. Set the source of the ForEach to be the list returned by the REST API method. 

2. Remove the assign from the Loop. 

3. In the CreateOrUpdate, remove the source you are setting as input parameter, and click on the + (plus) sign that will appear to the left side of the Source input parameter. This will expand the structure required and you can set their values directly from the current of the list output of the API method. 

Alternatively, add a local variable with the data type to be your entity, than use the assign to put the values of the api into this variable and pass this variable as the source to the CreateOrUpdate. 

4. Move the aggregate, that I am assuming you're using to feed the Table Records in the screen to AFTER the for each. 

As the records are being created in the database, it will fetch them. 

There are better ways to do that, usually. For example, you could use a local List to feed the Table in screen, and append the values from each item coming from the api inside the ForEach, instead fetching the data from the database, as you already have them available. 

Also, you must remember that if you enter multiple times in the page, and the API returns the same data, you will mostly likely create duplications in your database. So, you may want to check if the data already exists before saving to the database. 

If you don't need to keep the data in the database, you can pass the list of the api method directly to the table records in the screen. 

If you need, you may consider synchronisation with the external system instead of executing the method every time you go to the page. 

Hope this helps. 

Cheers 

mvp_badge
MVP
Rank: #156

Hi Ayushi,

Take a look at Service Center int yourEnvironmentURL/ServiceCenter to take more details about the error.

Maybe some datatype cast error is ocurring... 

mvp_badge
MVP
Rank: #5
Solution

Ayushi, 

Change your code in the follow way. 

1. Set the source of the ForEach to be the list returned by the REST API method. 

2. Remove the assign from the Loop. 

3. In the CreateOrUpdate, remove the source you are setting as input parameter, and click on the + (plus) sign that will appear to the left side of the Source input parameter. This will expand the structure required and you can set their values directly from the current of the list output of the API method. 

Alternatively, add a local variable with the data type to be your entity, than use the assign to put the values of the api into this variable and pass this variable as the source to the CreateOrUpdate. 

4. Move the aggregate, that I am assuming you're using to feed the Table Records in the screen to AFTER the for each. 

As the records are being created in the database, it will fetch them. 

There are better ways to do that, usually. For example, you could use a local List to feed the Table in screen, and append the values from each item coming from the api inside the ForEach, instead fetching the data from the database, as you already have them available. 

Also, you must remember that if you enter multiple times in the page, and the API returns the same data, you will mostly likely create duplications in your database. So, you may want to check if the data already exists before saving to the database. 

If you don't need to keep the data in the database, you can pass the list of the api method directly to the table records in the screen. 

If you need, you may consider synchronisation with the external system instead of executing the method every time you go to the page. 

Hope this helps. 

Cheers 

mvp_badge
MVP
Rank: #5

Hello Ayushi,

Could you show the properties of the CreateOrUpdate action?

Cheers.

mvp_badge
MVP
Rank: #5

For what you are showing, you are not using the result of the api. 

Where the value of the variable I'd, that you are using as the source for the PatientId in the create action, is being defined? 

mvp_badge
MVP
Rank: #5

OK. Sorry, didn't see the source.

As the records are being created, you have a list, but for the PatientInfoId to be 0, it looks like the service is not returning that information.

Did you executed this action in debug, to see what is being returned by the API?

P.S. I am assuming the ID and PAtientInfoId have the same data type...

mvp_badge
MVP
Rank: #5

P.S. 2.

Is any of the other information being saved correctly?