Loop Structure Variables into Entities

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.


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... 

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 

Solution

Eduardo Jauch wrote:

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 

Hello. 

I changed my flow to the one below. I am getting data from my REST API, cycling through each entry, and creating an entry in the database aggregate. This method doesn't seem to be working because the aggregate (pasted below) is creating more entries than expected (there should be 20 entries) and is assigning each entry to a PatientInfoId of 0 when that is not the value it should have. What do you think is going wrong? How can I fix it?  


 

Hello Ayushi,

Could you show the properties of the CreateOrUpdate action?

Cheers.

Eduardo Jauch wrote:

Hello Ayushi,

Could you show the properties of the CreateOrUpdate action?

Cheers.

 I am using the REST API GetPatient as the source. I created entity attributes Id, PatientInfoId, Name, and Gender in the aggregate PI. 


 

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? 

Eduardo Jauch wrote:

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? 

 There is a value of Id given in the JSON pulled in through the API.  

 

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...

P.S. 2.

Is any of the other information being saved correctly?

Eduardo Jauch wrote:

P.S. 2.

Is any of the other information being saved correctly?

 I figured it out. I had the character limit set too small for my response. Thank you!